From 13eb5a9b0fa4d53ab9dfce45658cc15582f056cc Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 15 Mar 2024 11:21:40 +0000 Subject: [PATCH] Stash --- Tuprules.tup | 2 ++ shell.nix | 5 +---- src/well_of_text.nim | 41 +++++++++++++++++++++++------------------ src/wells.nim | 23 +++++++++++++++++++++++ well_of_text.nimble | 2 +- 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/Tuprules.tup b/Tuprules.tup index 1a1f23e..1cb6174 100644 --- a/Tuprules.tup +++ b/Tuprules.tup @@ -1,5 +1,7 @@ include ../syndicate-nim/depends.tup +NIM = $(DIRENV) $(NIM) + NIM_FLAGS += --path:$(TUP_CWD)/../bumpy/src NIM_FLAGS += --path:$(TUP_CWD)/../chroma/src NIM_FLAGS += --path:$(TUP_CWD)/../crunchy/src diff --git a/shell.nix b/shell.nix index 92cbf5c..79988d9 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,2 @@ let pkgs = import { }; -in pkgs.nimPackages.buildNimPackage { - name = "dummy"; - buildInputs = [ pkgs.SDL2 ]; -} +in pkgs.hottext diff --git a/src/well_of_text.nim b/src/well_of_text.nim index 24fb63a..a8a7bbd 100644 --- a/src/well_of_text.nim +++ b/src/well_of_text.nim @@ -1,24 +1,14 @@ # SPDX-FileCopyrightText: ☭ Emery Hemingway # SPDX-License-Identifier: Unlicense -import std/[asyncdispatch, options, os, streams, tables] +import std/[asyncdispatch, options, os, parseopt, streams, tables] import preserves, syndicate, syndicate/[capabilities] import bumpy, pixie import sdl2 import ./wells -const typefacePath = - "/nix/store/ay5vhxszmibk0nrhx1vid4nhgvgdniq8-corefonts-1/share/fonts/truetype/Trebuchet_MS.ttf" - -proc unixSocketPath: Unix = - result.path = getEnv("SYNDICATE_SOCK") - if result.path == "": - result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace" - -proc envStep: Assertion = - var s = getEnv("SYNDICATE_STEP") - if s != "": parsePreserves(s, Cap) - else: capabilities.mint().toPreserve(Cap) +const typefacePath = getEnv"HOTTEXT_FONT_PATH" + # "/nix/store/ay5vhxszmibk0nrhx1vid4nhgvgdniq8-corefonts-1/share/fonts/truetype/Trebuchet_MS.ttf" type SdlError = object of CatchableError @@ -133,11 +123,10 @@ proc main() = #[ let - unix = unixSocketPath() - step = envStep() + route = envRoute() let actor = bootDataspace("chat") do (root: Cap; turn: var Turn): - connect(turn, unix, step) do (turn: var Turn; ds: Cap): - echo "connected to syndicate over UNIX-socket" + resolve(turn, root, route) do (turn: var Turn; ds: Cap): + echo "connected to syndicate over ", route asyncCheck actor.future ]# @@ -146,12 +135,28 @@ proc main() = sdlTimeout = 500 asyncPollTimeout = 500 + var reverse = false + for kind, key, val in getopt(): + case kind + of cmdLongOption: + case key + of "reverse": reverse = true + else: discard + of cmdShortOption: + case key + of "r": reverse = true + else: discard + else: discard + let stream = newFileStream(stdin) # TODO var line: string while readLine(stream, line): # TODO - app.well.append(line, font) + if reverse: + app.well.prepend(line, font) + else: + app.well.append(line, font) app.redraw() var diff --git a/src/wells.nim b/src/wells.nim index 14a4bef..b484749 100644 --- a/src/wells.nim +++ b/src/wells.nim @@ -98,11 +98,34 @@ proc append*(well; text: string; font: Font) = discard pane.spans.pop() well.panes.addLast Pane() +proc prepend*(well; text: string; font: Font) = + assert well.panes.len > 0 + let span = newSpan(text & "\n", font) + while true: + let pane = well.panes.peekFirst() + pane.spans.add(span) + var + textArea = well.textArea.vec2 + arrangement = typeset(pane.spans, textArea) + bounds = layoutBounds arrangement + if bounds.y <= textArea.y: + doAssert pane.spans.len > 0, "text does not find on a single pane - " & $bounds & $well.dimensions + pane.arrangement = arrangement + break + else: + discard pane.spans.pop() + well.panes.addFirst Pane() + proc append*(well; stream: Stream; font: Font) = var line: string while readLine(stream, line): append(well, line, font) +proc prepend*(well; stream: Stream; font: Font) = + var line: string + while readLine(stream, line): + prepend(well, line, font) + type Intersection = tuple src, dst: Rect index: int diff --git a/well_of_text.nimble b/well_of_text.nimble index 2cf11c9..115a944 100644 --- a/well_of_text.nimble +++ b/well_of_text.nimble @@ -2,4 +2,4 @@ bin = @["well_of_text"] license = "Unlicense" requires "nim", "pixie", "sdl2", "syndicate >= 20231019" srcDir = "src" -version = "20230911" +version = "20231020" -- 2.45.2