diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-14 20:57:45 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-14 21:05:16 +0100 |
commit | d26766c4c4015990703e84e8136f96d222edbc97 (patch) | |
tree | 7f412f8ca98d2b04323da5cf2fd607efbd6c408d /src | |
parent | a8f05f18fdd64485c26b453e62e8073b50e271ef (diff) | |
download | chawan-d26766c4c4015990703e84e8136f96d222edbc97.tar.gz |
Move around some modules
* 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
Diffstat (limited to 'src')
-rw-r--r-- | src/css/values.nim | 2 | ||||
-rw-r--r-- | src/extern/runproc.nim | 58 | ||||
-rw-r--r-- | src/html/dom.nim | 2 | ||||
-rw-r--r-- | src/html/env.nim | 6 | ||||
-rw-r--r-- | src/html/formdata.nim (renamed from src/xhr/formdata.nim) | 0 | ||||
-rw-r--r-- | src/html/xmlhttprequest.nim (renamed from src/xhr/xmlhttprequest.nim) | 0 | ||||
-rw-r--r-- | src/io/stdio.nim (renamed from src/extern/stdio.nim) | 0 | ||||
-rw-r--r-- | src/io/tempfile.nim (renamed from src/extern/tempfile.nim) | 0 | ||||
-rw-r--r-- | src/layout/engine.nim | 2 | ||||
-rw-r--r-- | src/layout/renderdocument.nim | 2 | ||||
-rw-r--r-- | src/loader/cgi.nim | 2 | ||||
-rw-r--r-- | src/loader/loader.nim | 2 | ||||
-rw-r--r-- | src/local/client.nim | 8 | ||||
-rw-r--r-- | src/local/container.nim | 2 | ||||
-rw-r--r-- | src/local/lineedit.nim (renamed from src/display/lineedit.nim) | 4 | ||||
-rw-r--r-- | src/local/pager.nim | 70 | ||||
-rw-r--r-- | src/local/term.nim (renamed from src/display/term.nim) | 9 | ||||
-rw-r--r-- | src/main.nim | 2 | ||||
-rw-r--r-- | src/server/buffer.nim | 4 | ||||
-rw-r--r-- | src/server/forkserver.nim | 2 | ||||
-rw-r--r-- | src/types/winattrs.nim | 7 |
21 files changed, 88 insertions, 96 deletions
diff --git a/src/css/values.nim b/src/css/values.nim index dd3c96ea..e1c54c04 100644 --- a/src/css/values.nim +++ b/src/css/values.nim @@ -6,11 +6,11 @@ import std/unicode import css/cssparser import css/selectorparser -import display/term import img/bitmap import layout/layoutunit import types/color import types/opt +import types/winattrs import utils/twtstr export selectorparser.PseudoElem diff --git a/src/extern/runproc.nim b/src/extern/runproc.nim deleted file mode 100644 index 9d189dff..00000000 --- a/src/extern/runproc.nim +++ /dev/null @@ -1,58 +0,0 @@ -import std/posix -import std/streams - -import display/term - -proc c_system(cmd: cstring): cint {. - importc: "system", header: "<stdlib.h>".} - -# Run process (without suspending the terminal controller). -proc runProcess*(cmd: string): bool = - let wstatus = c_system(cstring(cmd)) - if wstatus == -1: - result = false - else: - result = WIFEXITED(wstatus) and WEXITSTATUS(wstatus) == 0 - if not result: - # Hack. - #TODO this is a very bad idea, e.g. say the editor is writing into the - # file, then receives SIGINT, now the file is corrupted but Chawan will - # happily read it as if nothing happened. - # We should find a proper solution for this. - result = WIFSIGNALED(wstatus) and WTERMSIG(wstatus) == SIGINT - -# Run process (and suspend the terminal controller). -proc runProcess*(term: Terminal, cmd: string, wait = false): bool = - term.quit() - result = runProcess(cmd) - if wait: - term.anyKey() - term.restart() - -# Run process, and capture its output. -proc runProcessCapture*(cmd: string, outs: var string): bool = - let file = popen(cmd, "r") - if file == nil: - return false - let fs = newFileStream(file) - outs = fs.readAll() - let rv = pclose(file) - if rv == -1: - return false - return rv == 0 - -# Run process, and write an arbitrary string into its standard input. -proc runProcessInto*(cmd, ins: string): bool = - let file = popen(cmd, "w") - if file == nil: - return false - let fs = newFileStream(file) - fs.write(ins) - let rv = pclose(file) - if rv == -1: - return false - return rv == 0 - -proc myExec*(cmd: string) = - discard execl("/bin/sh", "sh", "-c", cmd, nil) - exitnow(127) diff --git a/src/html/dom.nim b/src/html/dom.nim index 2f36d81a..163e4a66 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -10,7 +10,6 @@ import css/cssparser import css/mediaquery import css/sheet import css/values -import display/term import html/catom import html/enums import html/event @@ -37,6 +36,7 @@ import types/matrix import types/referrer import types/url import types/vector +import types/winattrs import utils/mimeguess import utils/strwidth import utils/twtstr diff --git a/src/html/env.nim b/src/html/env.nim index 29104707..3ffff116 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -2,12 +2,13 @@ import std/selectors import std/streams import bindings/quickjs -import display/term import html/catom import html/chadombuilder import html/dom import html/event +import html/formdata import html/script +import html/xmlhttprequest import io/promise import js/base64 import js/console @@ -24,8 +25,7 @@ import loader/request import loader/response import types/blob import types/url -import xhr/formdata -import xhr/xmlhttprequest +import types/winattrs # NavigatorID proc appCodeName(navigator: ptr Navigator): string {.jsfget.} = "Mozilla" diff --git a/src/xhr/formdata.nim b/src/html/formdata.nim index bbf9a843..bbf9a843 100644 --- a/src/xhr/formdata.nim +++ b/src/html/formdata.nim diff --git a/src/xhr/xmlhttprequest.nim b/src/html/xmlhttprequest.nim index e9905760..e9905760 100644 --- a/src/xhr/xmlhttprequest.nim +++ b/src/html/xmlhttprequest.nim diff --git a/src/extern/stdio.nim b/src/io/stdio.nim index 729b50f6..729b50f6 100644 --- a/src/extern/stdio.nim +++ b/src/io/stdio.nim diff --git a/src/extern/tempfile.nim b/src/io/tempfile.nim index 5968270b..5968270b 100644 --- a/src/extern/tempfile.nim +++ b/src/io/tempfile.nim diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 371121a3..e9c3ffde 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -5,9 +5,9 @@ import std/unicode import css/stylednode import css/values -import display/term import layout/box import layout/layoutunit +import types/winattrs import utils/luwrap import utils/strwidth import utils/twtstr diff --git a/src/layout/renderdocument.nim b/src/layout/renderdocument.nim index ef6504c8..ef82931d 100644 --- a/src/layout/renderdocument.nim +++ b/src/layout/renderdocument.nim @@ -3,10 +3,10 @@ import std/unicode import css/stylednode import css/values -import display/term import layout/box import layout/engine import layout/layoutunit +import types/winattrs import types/cell import types/color import utils/strwidth diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim index f7922224..b91e3b1b 100644 --- a/src/loader/cgi.nim +++ b/src/loader/cgi.nim @@ -4,8 +4,8 @@ import std/posix import std/streams import std/strutils -import extern/stdio import io/posixstream +import io/stdio import loader/connecterror import loader/headers import loader/loaderhandle diff --git a/src/loader/loader.nim b/src/loader/loader.nim index b1bcce38..135a8c96 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -24,12 +24,12 @@ import std/streams import std/strutils import std/tables -import extern/tempfile import io/posixstream import io/promise import io/serialize import io/serversocket import io/socketstream +import io/tempfile import io/urlfilter import js/error import js/javascript diff --git a/src/local/client.nim b/src/local/client.nim index 4f7d9f2b..bc52f704 100644 --- a/src/local/client.nim +++ b/src/local/client.nim @@ -15,11 +15,11 @@ when defined(posix): import bindings/constcharp import bindings/quickjs import config/config -import display/lineedit -import display/term import html/chadombuilder import html/dom import html/event +import html/formdata +import html/xmlhttprequest import io/bufstream import io/posixstream import io/promise @@ -41,7 +41,9 @@ import loader/headers import loader/loader import loader/request import local/container +import local/lineedit import local/pager +import local/term import server/buffer import server/forkserver import types/blob @@ -49,8 +51,6 @@ import types/cookie import types/opt import types/url import utils/twtstr -import xhr/formdata -import xhr/xmlhttprequest import chagashi/charset diff --git a/src/local/container.nim b/src/local/container.nim index 7946200a..e2d84ac0 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -6,7 +6,6 @@ when defined(posix): import std/posix import config/config -import display/term import io/promise import io/serialize import io/socketstream @@ -23,6 +22,7 @@ import types/color import types/cookie import types/referrer import types/url +import types/winattrs import utils/luwrap import utils/mimeguess import utils/strwidth diff --git a/src/display/lineedit.nim b/src/local/lineedit.nim index a69465a6..0f048586 100644 --- a/src/display/lineedit.nim +++ b/src/local/lineedit.nim @@ -2,10 +2,10 @@ import std/strutils import std/unicode import bindings/quickjs -import display/term import js/javascript import types/cell import types/opt +import types/winattrs import utils/strwidth import utils/twtstr @@ -22,7 +22,7 @@ type LineEdit* = ref object news*: string - prompt*: string + prompt: string promptw: int state*: LineEditState escNext*: bool diff --git a/src/local/pager.nim b/src/local/pager.nim index bf9d3168..7502cb00 100644 --- a/src/local/pager.nim +++ b/src/local/pager.nim @@ -16,16 +16,13 @@ import config/chapath import config/config import config/mailcap import config/mimetypes -import display/lineedit -import display/term -import extern/runproc -import extern/stdio -import extern/tempfile import io/bufstream import io/posixstream import io/promise import io/serialize import io/socketstream +import io/stdio +import io/tempfile import io/urlfilter import js/error import js/javascript @@ -37,7 +34,9 @@ import loader/headers import loader/loader import loader/request import local/container +import local/lineedit import local/select +import local/term import server/buffer import server/forkserver import types/cell @@ -47,6 +46,7 @@ import types/opt import types/referrer import types/urimethodmap import types/url +import types/winattrs import utils/strwidth import utils/twtstr @@ -126,7 +126,8 @@ type jsDestructor(Pager) -func attrs(pager: Pager): WindowAttributes = pager.term.attrs +template attrs(pager: Pager): WindowAttributes = + pager.term.attrs func loaderPid(pager: Pager): int64 {.jsfget.} = int64(pager.loader.process) @@ -745,6 +746,59 @@ proc discardTree(pager: Pager, container = none(Container)) {.jsfunc.} = else: pager.alert("Buffer has no children!") +proc c_system(cmd: cstring): cint {.importc: "system", header: "<stdlib.h>".} + +# Run process (without suspending the terminal controller). +proc runProcess(cmd: string): bool = + let wstatus = c_system(cstring(cmd)) + if wstatus == -1: + result = false + else: + result = WIFEXITED(wstatus) and WEXITSTATUS(wstatus) == 0 + if not result: + # Hack. + #TODO this is a very bad idea, e.g. say the editor is writing into the + # file, then receives SIGINT, now the file is corrupted but Chawan will + # happily read it as if nothing happened. + # We should find a proper solution for this. + result = WIFSIGNALED(wstatus) and WTERMSIG(wstatus) == SIGINT + +# Run process (and suspend the terminal controller). +proc runProcess(term: Terminal, cmd: string, wait = false): bool = + term.quit() + result = runProcess(cmd) + if wait: + term.anyKey() + term.restart() + +# Run process, and capture its output. +proc runProcessCapture(cmd: string, outs: var string): bool = + let file = popen(cmd, "r") + if file == nil: + return false + let fs = newFileStream(file) + outs = fs.readAll() + let rv = pclose(file) + if rv == -1: + return false + return rv == 0 + +# Run process, and write an arbitrary string into its standard input. +proc runProcessInto(cmd, ins: string): bool = + let file = popen(cmd, "w") + if file == nil: + return false + let fs = newFileStream(file) + fs.write(ins) + let rv = pclose(file) + if rv == -1: + return false + return rv == 0 + +template myExec(cmd: string) = + discard execl("/bin/sh", "sh", "-c", cstring(cmd), nil) + exitnow(127) + proc toggleSource(pager: Pager) {.jsfunc.} = if not pager.container.canreinterpret: return @@ -1182,7 +1236,6 @@ proc ansiDecode(pager: Pager; url: URL; ishtml: var bool; fdin: cint): cint = discard close(pipefdOutAnsi[1]) closeStderr() myExec(cmd) - assert false else: discard close(pipefdOutAnsi[1]) discard close(fdin) @@ -1206,7 +1259,6 @@ proc runMailcapReadPipe(pager: Pager; stream: SocketStream; cmd: string; closeStderr() discard close(pipefdOut[1]) myExec(cmd) - doAssert false # parent pid @@ -1227,7 +1279,6 @@ proc runMailcapWritePipe(pager: Pager; stream: SocketStream; closeStdout() closeStderr() myExec(cmd) - doAssert false else: # parent stream.close() @@ -1326,7 +1377,6 @@ proc filterBuffer(pager: Pager; stream: SocketStream; cmd: string; closeStderr() discard close(pipefd_out[1]) myExec(cmd) - doAssert false # parent discard close(pipefd_out[1]) let fdout = pipefd_out[0] diff --git a/src/display/term.nim b/src/local/term.nim index cb96a385..050edf3b 100644 --- a/src/display/term.nim +++ b/src/local/term.nim @@ -12,6 +12,7 @@ import config/config import types/cell import types/color import types/opt +import types/winattrs import utils/strwidth import utils/twtstr @@ -46,14 +47,6 @@ type funcstr: array[256, uint8] caps: array[TermcapCap, cstring] - WindowAttributes* = object - width*: int - height*: int - ppc*: int # cell width - ppl*: int # cell height - width_px*: int - height_px*: int - Terminal* = ref TerminalObj TerminalObj = object cs*: Charset diff --git a/src/main.nim b/src/main.nim index 9d782a90..ea5a92dd 100644 --- a/src/main.nim +++ b/src/main.nim @@ -8,9 +8,9 @@ import std/os import config/chapath import config/config -import display/term import io/serversocket import local/client +import local/term import types/opt import utils/strwidth import utils/twtstr diff --git a/src/server/buffer.nim b/src/server/buffer.nim index e4af4232..7e4b7190 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -19,13 +19,13 @@ import css/mediaquery import css/sheet import css/stylednode import css/values -import display/term import html/catom import html/chadombuilder import html/dom import html/enums import html/env import html/event +import html/formdata as formdata_impl import io/bufstream import io/posixstream import io/promise @@ -46,9 +46,9 @@ import types/cookie import types/formdata import types/opt import types/url +import types/winattrs import utils/strwidth import utils/twtstr -import xhr/formdata as formdata_impl from chagashi/decoder import newTextDecoder import chagashi/charset diff --git a/src/server/forkserver.nim b/src/server/forkserver.nim index 41784e8f..2c00dd4e 100644 --- a/src/server/forkserver.nim +++ b/src/server/forkserver.nim @@ -5,7 +5,6 @@ import std/streams import std/tables import config/config -import display/term import io/posixstream import io/serialize import io/serversocket @@ -13,6 +12,7 @@ import loader/loader import server/buffer import types/urimethodmap import types/url +import types/winattrs import utils/strwidth import chagashi/charset diff --git a/src/types/winattrs.nim b/src/types/winattrs.nim new file mode 100644 index 00000000..7d9e0218 --- /dev/null +++ b/src/types/winattrs.nim @@ -0,0 +1,7 @@ +type WindowAttributes* = object + width*: int + height*: int + ppc*: int # cell width + ppl*: int # cell height + width_px*: int + height_px*: int |