diff options
author | bptato <nincsnevem662@gmail.com> | 2021-12-20 20:11:31 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-12-20 20:11:38 +0100 |
commit | bbb14729f8b0c612f79ba96566d0118fc8c2290d (patch) | |
tree | 6c686d8f40ca37255dcf550bf653e244d7105247 /src/main.nim | |
parent | cbcdafaf3fab6129c8c387bc352bd1f17f663684 (diff) | |
download | chawan-bbb14729f8b0c612f79ba96566d0118fc8c2290d.tar.gz |
Add client for buffer control
Diffstat (limited to 'src/main.nim')
-rw-r--r-- | src/main.nim | 76 |
1 files changed, 2 insertions, 74 deletions
diff --git a/src/main.nim b/src/main.nim index 1bb8cf1e..5e783e53 100644 --- a/src/main.nim +++ b/src/main.nim @@ -1,83 +1,11 @@ -import httpclient -import uri import os -import streams -import terminal when defined(profile): import nimprof -import html/parser -import io/buffer -import io/term +import client import config/config import utils/twtstr -let clientInstance = newHttpClient() -proc loadRemotePage*(url: string): string = - return clientInstance.getContent(url) - -proc loadLocalPage*(url: string): string = - return readFile(url) - -proc getRemotePage*(url: string): Stream = - return clientInstance.get(url).bodyStream - -proc getLocalPage*(url: string): Stream = - return newFileStream(url, fmRead) - -proc getPageUri(uri: Uri): Stream = - var moduri = uri - moduri.anchor = "" - if uri.scheme == "" or uri.scheme == "file": - return getLocalPage($moduri) - else: - return getRemotePage($moduri) - -var buffers: seq[Buffer] - -proc die() = - eprint "Invalid parameters. Usage:\ntwt <url>" - quit(1) - -proc main*() = - let attrs = getTermAttributes() - let buffer = newBuffer(attrs) - buffers.add(buffer) - - var lastUri: Uri - if paramCount() < 1: - if not isatty(stdin): - buffer.showsource = true - try: - while true: - buffer.source &= stdin.readChar() - except EOFError: - #TODO handle failure (also, is this even portable at all?) - discard reopen(stdin, "/dev/tty", fmReadWrite); - else: - die() - buffer.setLocation(lastUri) - else: - lastUri = parseUri(paramStr(1)) - buffer.source = getPageUri(lastUri).readAll() #TODO get rid of this - - buffer.setLocation(lastUri) - buffer.document = parseHtml(newStringStream(buffer.source)) - buffer.renderDocument() - while displayPage(attrs, buffer): - buffer.setStatusMessage("Loading...") - var newUri = buffer.location - lastUri.anchor = "" - newUri.anchor = "" - if $lastUri != $newUri: - buffer.clearBuffer() - if lastUri.scheme == "" and lastUri.path == "" and lastUri.anchor != "": - discard - else: - buffer.document = parseHtml(getPageUri(buffer.location)) - buffer.renderPlainText(getPageUri(lastUri).readAll()) - lastUri = newUri - readConfig() width_table = makewidthtable(gconfig.ambiguous_double) -main() +newClient().launchClient(commandLineParams()) |