diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-09 01:44:58 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-09 01:52:24 +0200 |
commit | 11219c7d21c8ec7f438d52de063c4ac25f84711d (patch) | |
tree | 36b1308d747cc467dc7dad2713eb2cc546390026 /src/display/pager.nim | |
parent | 6c435aa6c186c2fe7ec72cee2a5ae2f1ae8b22a7 (diff) | |
download | chawan-11219c7d21c8ec7f438d52de063c4ac25f84711d.tar.gz |
add extern, refactor some term functions
* Add an extern() call. Maybe it should be defined on client. It certainly should accept a dictionary instead of the enum type we use now. Perhaps it should return the error code? I'll leave it undocumented until I figure this out. * Refactor enableRawMode, unblockStdin, etc. so that they operate on the term object instead of global state. * Move editor to a separate folder, and factor out runprocess into a different module.
Diffstat (limited to 'src/display/pager.nim')
-rw-r--r-- | src/display/pager.nim | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/display/pager.nim b/src/display/pager.nim index 9196b4f9..0229c706 100644 --- a/src/display/pager.nim +++ b/src/display/pager.nim @@ -17,6 +17,8 @@ import config/config import config/mailcap import config/mimetypes import display/term +import extern/editor +import extern/runproc import io/connecterror import io/lineedit import io/loader @@ -24,7 +26,6 @@ import io/promise import io/request import io/tempfile import io/window -import ips/editor import ips/forkserver import ips/socketstream import js/javascript @@ -831,6 +832,33 @@ proc reload(pager: Pager) {.jsfunc.} = pager.gotoURL(newRequest(pager.container.source.location), none(URL), pager.container.contenttype, replace = pager.container) +proc setEnvVars(pager: Pager) {.jsfunc.} = + try: + putEnv("CHA_URL", $pager.container.location) + putEnv("CHA_CHARSET", $pager.container.charset) + except OSError: + pager.alert("Warning: failed to set some environment variables") + +type ExternType = enum + SUSPEND_SETENV = "suspend-setenv" + SUSPEND_SETENV_WAIT = "suspend-setenv-wait" + SUSPEND_NO_SETENV = "suspend-no-setenv" + SUSPEND_NO_SETENV_WAIT = "suspend-no-setenv-wait" + NO_SUSPEND_SETENV = "no-suspend-setenv" + NO_SUSPEND_NO_SETENV = "no-suspend-no-setenv" + +#TODO this could be handled much better. +# * suspend, setenv, wait as dict flags +# * retval as int? +proc extern(pager: Pager, cmd: string, t = SUSPEND_SETENV): bool {.jsfunc.} = + if t in {SUSPEND_SETENV, SUSPEND_SETENV_WAIT, NO_SUSPEND_SETENV}: + pager.setEnvVars() + if t in {NO_SUSPEND_SETENV, NO_SUSPEND_NO_SETENV}: + return runProcess(cmd) + else: + return runProcess(pager.term, cmd, + t in {SUSPEND_SETENV_WAIT, SUSPEND_NO_SETENV_WAIT}) + proc authorize(pager: Pager) = pager.setLineEdit("Username: ", USERNAME) |