Download
jcs
/wikipedia
/browser.h
(View History)
jcs main+browser: Make cmd+click on links open them in a new window | Latest amendment: 54 on 2023-10-30 |
1 | /* |
2 | * Copyright (c) 2021-2022 joshua stein <jcs@jcs.org> |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above |
6 | * copyright notice and this permission notice appear in all copies. |
7 | * |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ |
16 | |
17 | #ifndef __BROWSER_H__ |
18 | #define __BROWSER_H__ |
19 | |
20 | #include <stdlib.h> |
21 | #include "http.h" |
22 | |
23 | enum { |
24 | BROWSER_STATE_IDLE, |
25 | BROWSER_STATE_ARTICLE_GET, |
26 | BROWSER_STATE_ARTICLE_PROCESS, |
27 | BROWSER_STATE_ARTICLE_DONE |
28 | }; |
29 | |
30 | #define STYLE_BOLD (1UL << 0) |
31 | #define STYLE_ITALIC (1UL << 1) |
32 | #define STYLE_H1 (1UL << 2) |
33 | #define STYLE_H2 (1UL << 3) |
34 | #define STYLE_H3 (1UL << 4) |
35 | #define STYLE_H4 (1UL << 5) |
36 | #define STYLE_H5 (1UL << 6) |
37 | #define STYLE_LINK (1UL << 7) |
38 | #define STYLE_REF (1UL << 8) |
39 | #define STYLE_TEMPLATE (1UL << 9) |
40 | |
41 | struct browser_link { |
42 | char *link; |
43 | unsigned short pos; |
44 | unsigned short len; |
45 | }; |
46 | |
47 | struct browser { |
48 | short state; |
49 | WindowPtr win; |
50 | TEHandle input_te; |
51 | unsigned long last_input_for_search; |
52 | Rect te_bounds; |
53 | TEHandle te; |
54 | TEHandle debug_te; |
55 | ControlHandle te_scroller; |
56 | ListHandle search_results; |
57 | struct wikipedia_request *wpr; |
58 | size_t links_count; |
59 | size_t links_size; |
60 | struct browser_link *links; |
61 | char last_printed[2]; |
62 | }; |
63 | |
64 | struct browser *browser_init(char *query); |
65 | bool browser_print(struct browser *browser, const char *str, size_t len, |
66 | unsigned long style); |
67 | void browser_clear(struct browser *browser); |
68 | void browser_draw_line(struct browser *browser); |
69 | bool browser_debug_enabled(struct browser *browser); |
70 | size_t browser_debug_print(struct browser *browser, const char *str, |
71 | size_t len); |
72 | |
73 | #endif |