about summary refs log tree commit diff stats
path: root/src/main.nim
Commit message (Collapse)AuthorAgeFilesLines
* buffer: wait for scripts in headless modebptato2025-02-151-5/+3
| | | | | Dump mode remains the same, except now it can be controlled in config.toml as well.
* pager: catch SIGINT for interrupt handlerbptato2025-02-051-1/+6
| | | | | | | | Significantly more efficient in long running commands (as the context switch is gone). For many commands in quick succession... it replaces the fcntl with a tcsetattr, so I guess it's the same?
* main: add version checkbptato2025-01-261-0/+4
| | | | ref. https://todo.sr.ht/~bptato/chawan/44
* buffer: improve screen state synchronizationbptato2025-01-231-1/+1
| | | | | | | | | | The intent behind the original design was that the page shouldn't change without user interaction. This sounds good in theory, but in practice it's unnecessary if you disable JS (nothing will modify the page), and annoying if you enable it (breaks pages that load with AJAX). So now we queue a task to notify us when the page has been updated, and act accordingly when the task is completed.
* pager, term: replace execCmd, Filebptato2025-01-221-2/+3
| | | | | | | | | | pager: I want to change mailcap command parsing, so a custom implementation is needed. term: now it uses a custom buffer for the output stream too. I don't think there is much difference in performance, but stdio was in the way. (Also, this way it will be easier to make it async in the future.)
* Remove submodulesbptato2025-01-181-2/+0
| | | | | I got tired of submodules. This commit doesn't build; subtrees incoming...
* pager: improve content type handlingbptato2025-01-151-2/+2
| | | | also remove some unused fields of Container
* config: switch to camel casebptato2025-01-131-2/+2
| | | | | | We already need a camel -> kebab converter anyway. Unfortunately this also changes JS binding names, so it's a breaking change. Oh well.
* loader: fix memory leak on x-saveoutput + various fd leaksbptato2025-01-111-1/+3
|
* buffer: remove server socketbptato2025-01-091-8/+5
| | | | | | | | | | | Now we just pass through a socket created in pager. This removes the need for a socket directory, and strengthens the buffer sandbox slightly. I've kept the ServerSocket code, because I want to add some form of RPC and communication between separate instances in the future. However, I don't expect this to be handled outside the main process, so I've removed the Capsicum-specific connectat/bindat code.
* loader: use per-process control socketsbptato2025-01-081-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | Previously, each message (load, resume, passFd, etc.) would open a new connection to loader's UNIX socket, and assumed the loader was dead when the loader did not respond (ECONNREFUSED). As it turns out, this model was hopelessly broken: POSIX does not specify when a UNIX socket can refuse connections, so while it happened to work on Linux (which just blocks if it can't accept right now), FreeBSD would randomly refuse connections whenever its listen queue was full. Instead, we now take a socketpair() from the loader in addClient, and pass on one half to the client (the other half stays in loader); this is the control stream, and all messages from the specific client are sent through it. If a message includes a new stream (e.g. lcLoad), then it sends a new socketpair through the control stream. Aside from not being completely broken (and being marginally more efficient), this arrangement has several other benefits: it removes the need for authentication, almost removes the need for sockdir (now only buffers use it), and will make it easier to add async message processing in the future.
* Try to set close-on-exec, misc cleanupbptato2025-01-041-0/+1
| | | | | | | | | | FD_CLOEXEC should hopefully get rid of bugs where buffers outlived the main process because of some stray child process keeping the canary pipe alive. It's not perfect because of the runMailcapWriteFile/runMailcapReadFile double-forks. Ideally they should be replaced with an implementation that tracks temporary files in the main process.
* CHA_CONFIG_DIR -> CHA_DIRbptato2024-12-271-2/+2
| | | | | | | It isn't really limited to config. It just happens to be in XDG_CONFIG_HOME because XDG basedirs suck. (W3M_DIR works similarly.)
* main: add missing noreturnbptato2024-12-221-1/+1
|
* Add historybptato2024-12-171-1/+5
| | | | | It's still missing a "color visited links" feature, but it's better than nothing.
* client: mostly merge into pagerbptato2024-12-091-1/+3
| | | | | | | | not completely, because that would break the existing API :/ this also fixes the broken interruptHandler - it no longer crashes, but it's still inefficient... probably it should "just" handle SIGINT instead
* Fix casingbptato2024-12-051-1/+1
|
* config, mailcap: remove std/streams dependency, specialize mmapbptato2024-12-051-1/+1
| | | | | | | | | | * use PosixStream/mmap for mailcap reading too; this finally lets us get rid of std/streams in the entire codebase * split up recvDataLoopOrMmap into 3 functions: one that can fall back to recvAll, one that falls back to recvDataLoop, and one that does not fall back to anything * use MAP_PRIVATE in mmap for read (we don't care if changes are propagated, as we do no changes to cached files)
* mimetypes: refactor, use mime.types for inline image extensionsbptato2024-12-051-0/+2
| | | | | | | | | | | | * remove std/streams use from mime.types; mmap and parse directly * use mime.types for inline image extensions * add some jpeg file extensions Latter came up because I was trying to add a format locally and it wouldn't recognize it on images from my file system (i.e. by extension). As a security measure we still do not allow additional extensions for predefined inline image types.
* main: support -C/path etc.bptato2024-12-051-10/+15
| | | | it's unambiguous anyway
* toml, config: skip copying buf, use PosixStreambptato2024-12-031-7/+9
| | | | | | | one std/streams less I used mmap for reading the user config. It shouldn't matter in any realistically sized config, but who knows.
* config.configdir -> config.dirbptato2024-11-261-3/+3
|
* twtstr: beforeLast -> untilLastbptato2024-11-151-1/+1
| | | | for consistency
* formdata: eliminate a global varbptato2024-11-151-1/+4
|
* chapath: fix a few more bugs, simplifybptato2024-11-131-1/+4
| | | | | | | | | * fix incorrect :- behavior * merge non-standard '${%VARIABLE}' syntax with regular syntax; now all internal variables are exported to the environment, so the behavior should be equivalent. * handle terminal symbol appropriately in all states * deny numeric curly substitutions
* config: refactor, accept more possible config dirsbptato2024-10-281-18/+26
| | | | | | | | | | | | | | | | | | | | | I'm starting to favor dotfiles over XDG basedirs, but there's no reason why we couldn't have both. So now the search path is: 0. if config was set through -C, use that 1. $CHA_CONFIG_DIR is set -> $CHA_CONFIG_DIR/config.toml 2. $XDG_CONFIG_HOME is set -> $XDG_CONFIG_HOME/chawan/config.toml 3. ~/.config/chawan/config.toml exists -> use that 4. ~/.chawan/config.toml exists -> use that Notably, this makes it so the default directory is ~/.chawan *if* you don't have an existing config.toml file. So in that case known_hosts will be placed in ~/.chawan/known_hosts. However, configurations with a config in ~/.config/chawan/config.toml continue to work as expected, as for those the known_hosts file remains inside ~/.config/chawan/. Finally, I've added a default user CGI directory to reduce friction in setting CGI up. (Like known_hosts, it's also relative to whatever config dir you have.)
* termcap: merge into termbptato2024-10-231-1/+0
| | | | | again, not that useful to put it in a separate module if only term uses it
* gmifetch: rewrite in Nimbptato2024-10-121-1/+2
| | | | | | | | | | This finally makes it possible to use socks5 for Gemini. Also slightly refactored the config, to make it easier to pass on the config dir. By the way, the known_hosts file is now stored in the config dir too. The adapter will try to move it to there from the old location.
* term: don't panic if termcap tgetent failsbptato2024-08-171-0/+11
| | | | | | | | If TERM is unrecognized by termcap, retry as dosansi. When that fails, just fall back to the non-termcap code path. (There is no reason to panic without termcap; it's just one of the several capability detection mechanisms we use.)
* main, forkserver: optimize startupbptato2024-07-061-2/+2
| | | | | Merge "load config" with "fork loader", so that the loader process gets forked one packet earlier.
* main: misc improvementsbptato2024-07-051-9/+29
|
* Move JS wrapper into Monouchabptato2024-06-031-6/+5
| | | | Operation "modularize Chawan somewhat" part 3
* main: fix tmpdir/sockdir permsbptato2024-05-311-3/+4
|
* config: fix -C with files not in CWDbptato2024-05-311-1/+1
|
* forkserver: simplify fcLoadConfigbptato2024-05-181-1/+1
|
* config: separate tmp dir for sockets, usersbptato2024-05-161-2/+3
| | | | | | | * add $LOGNAME to the tmp directory name, so that tmpdirs of separate users don't conflict * use separate directory for sockets, so that we do not have to give buffers access to all cached pages
* Use isSome instead of isOkbptato2024-05-051-1/+1
| | | | no point in having identical overloads
* client: make quit() actually quit, misc fixesbptato2024-05-041-13/+16
| | | | | | | * unwind the QJS stack with an uncatchable exception when quit is called * clean up JS references in JSRuntime free even when the Nim counterparts are still alive * simplify some tests
* Add capsicum supportbptato2024-03-281-3/+4
| | | | | | | | | | | | | It's the sandboxing system of FreeBSD. Quite pleasant to work with. (Just trying to figure out the basics with this one before tackling the abomination that is seccomp.) Indeed, the only non-trivial part was getting newSelector to work with Capsicum. Long story short it doesn't, so we use an ugly pointer cast + assignment. But even that is stdlib's "fault", not Capsicum's. This also gets rid of that ugly SocketPath global.
* config: improve input systembptato2024-03-261-1/+11
| | | | as described in <https://todo.sr.ht/~bptato/chawan/6>
* main: refactor slightlybptato2024-03-211-149/+134
| | | | | | * put forkServer into main() * use a ctx type instead of closures * get rid of types/opt import
* main: set CHA_LIBEXEC_DIR env var at startupbptato2024-03-191-1/+5
| | | | This way, we can use it everywhere (e.g. in mailcap).
* client: refactor inputbptato2024-03-181-3/+3
| | | | | * move mouse handling to term * do not use File for input just to disable buffering anyway
* config: clean up/simplifybptato2024-03-171-13/+13
| | | | | | | | | * Parse the default config at runtime. There's no significant performance difference, but this makes it much less painful to write config code. * Add better error reporting * Make fromJS2 easier to use * Unquote ChaPaths while parsing config
* Move SIGCHLD ignore call to forkserverbptato2024-03-171-4/+0
| | | | seems like it confuses popen()
* main: ignore SIGCHLDbptato2024-03-171-0/+4
| | | | to avoid zombies
* Move around some modulesbptato2024-03-141-1/+1
| | | | | | | | * extern -> gone, runproc absorbed by pager, others moved into io/ * display -> local/ (where else would we display?) * xhr -> html/ * move out WindowAttributes from term, so we don't depend on local from server
* Replace Chakasu with Chagashibptato2024-02-221-1/+1
| | | | | | The API is horrid :( but at least it copies less. TODO: think of a better API.
* forkserver: clean upbptato2024-01-291-2/+1
| | | | | Move forkBuffer into forkserver (why was it in container anyway), remove unused mainproc variable, etc.
* Remove std/terminal dependencybptato2024-01-171-1/+1
| | | | It is mostly unnecessary, and conflicts with our use of termcap anyway.