-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interactive terminal application that works
- Loading branch information
Showing
20 changed files
with
1,087 additions
and
912 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
*.exe | ||
.idea/* | ||
.vscode/* | ||
retmp/* | ||
*.exe | ||
.idea/* | ||
.vscode/* | ||
retmp/* | ||
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Tool to download a file / whole folder from the remarkable to a destination | ||
import ../tablet/filesystem | ||
import ../document/document | ||
import ../tablet/downloader | ||
import std/terminal | ||
import std/strutils | ||
|
||
proc download*(elem: Element, target: string, root: bool, preset: Preset) = | ||
var safe_str = target | ||
if target[target.len - 1] != '/': | ||
safe_str = safe_str & "/" | ||
if elem.el_type == ElementType.FolderElem or elem.el_type == ElementType.RootElem: | ||
for child in elem.children: | ||
var subdir = safe_str | ||
if not root: | ||
subdir = subdir & elem.name & "/" | ||
download(child, subdir, false, preset) | ||
else: | ||
let path = safe_str & elem.name & ".pdf" | ||
let safe_path = elem.path.substr(0, elem.path.rfind(".") - 1) | ||
let doc = download_file(safe_path, preset) | ||
if doc == nil: | ||
stdout.styledWriteLine(fgYellow, "Unable to download " & elem.name) | ||
else: | ||
echo "Generating pdf at: " & path | ||
doc.generate_pdf(path) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import std/parseopt | ||
import std/strutils | ||
import ../tablet/filesystem | ||
import std/terminal | ||
import ls | ||
import download | ||
import ../document/preset | ||
|
||
proc split_strings(a: string): seq[string] = | ||
var buffer = "" | ||
var in_string = false | ||
for ch in a: | ||
if ch == '"': | ||
in_string = not in_string | ||
elif (ch == ' ' and not in_string): | ||
result.add(buffer) | ||
buffer = "" | ||
else: | ||
buffer = buffer & ch | ||
result.add(buffer) | ||
|
||
|
||
proc launch_interactive*() = | ||
# Download the filesystem | ||
var fsroot = get_filesystem_root(false) | ||
var tree: seq[Element] | ||
tree.add(fsroot) | ||
var preset = def_preset() | ||
while true: | ||
var cur_dir = "/" | ||
for elem in tree: | ||
cur_dir = cur_dir & elem.name & "/" | ||
stdout.styledWrite(fgCyan, cur_dir & " $ ") | ||
let input = readLine(stdin).splitStrings() | ||
var valid = false | ||
if input.len == 1: | ||
if input[0] == "ls": | ||
ls(tree[tree.len - 1]) | ||
valid = true | ||
elif input[0] == "exit": | ||
break | ||
elif input[0] == "help": | ||
echo "ls - Displays contents of current dir" | ||
echo "cd [dir] - Moves into a directory" | ||
echo "save [file/dir] [destination] - Saves file into destination in your PC" | ||
echo "sync - Does sync with all files, same as done by the GUI" | ||
echo "setpreset [preset] - Set preset to a given one" | ||
echo "lspresets - Display all usable presets" | ||
valid = true | ||
elif input.len == 2: | ||
if input[0] == "cd": | ||
var found = false | ||
if input[1] == ".." and tree.len > 1: | ||
found = true | ||
valid = true | ||
discard tree.pop() | ||
else: | ||
for elem in tree[tree.len - 1].children: | ||
if elem.name == input[1]: | ||
if elem.el_type == ElementType.FolderElem: | ||
tree.add(elem) | ||
valid = true | ||
found = true | ||
else: | ||
stdout.styledWriteLine(fgRed, "Cannot move into element") | ||
if not found: | ||
stdout.styledWriteLine(fgRed, "Could not find element") | ||
elif input.len == 3: | ||
if input[0] == "save": | ||
var found = false | ||
var telem: Element | ||
if input[1] == ".": | ||
found = true | ||
valid = true | ||
telem = tree[tree.len - 1] | ||
else: | ||
for elem in tree[tree.len - 1].children: | ||
if elem.name == input[1]: | ||
telem = elem | ||
valid = true | ||
found = true | ||
if not found: | ||
stdout.styledWriteLine(fgRed, "Could not find element") | ||
else: | ||
download(telem, input[2], true, preset) | ||
|
||
if not valid: | ||
stdout.styledWriteLine(fgRed, "Invalid command") | ||
|
||
# We support ls [dir] cd [dir] save [file/dir] [to] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Tool to inspect the remarkable filesystem from the command line | ||
import ../tablet/filesystem | ||
import terminal | ||
|
||
proc ls*(fs: Element) = | ||
for val in fs.children: | ||
if val.el_type == ElementType.FolderElem: | ||
stdout.styledWriteLine(fgBlue, val.name & "/") | ||
for val in fs.children: | ||
if val.el_type == ElementType.DocumentElem: | ||
stdout.styledWriteLine(val.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
|
||
type RemarkableColor* = enum | ||
BLACK, | ||
GRAY, | ||
WHITE, | ||
HIGHLIGHT_YELLOW, | ||
HIGHLIGHT_PINK, | ||
HIGHLIGHT_GREEN, | ||
BLUE, | ||
RED, | ||
HIGHLIGHT_OVERLAP | ||
|
||
# Includes rmhacks tools | ||
type RemarkableTool* = enum | ||
BRUSH, | ||
PENCIL, | ||
BALLPOINT, | ||
MARKER, | ||
FINELINER, | ||
HIGHLIGHTER, | ||
ERASER, | ||
MECHANICAL, | ||
ERASER_AREA, | ||
CALLIGRAPHY, | ||
UNKNOWN | ||
|
||
# This is used as the index LUT for the .lines files | ||
let pen_lut* = [BRUSH, PENCIL, BALLPOINT, MARKER, FINELINER, HIGHLIGHTER, ERASER, MECHANICAL, | ||
ERASER_AREA, UNKNOWN, UNKNOWN, UNKNOWN, BRUSH, MECHANICAL, PENCIL, BALLPOINT, MARKER, | ||
FINELINER, HIGHLIGHTER, ERASER, UNKNOWN, CALLIGRAPHY] | ||
|
||
|
||
type RemarkableColor* = enum | ||
BLACK, | ||
GRAY, | ||
WHITE, | ||
HIGHLIGHT_YELLOW, | ||
HIGHLIGHT_PINK, | ||
HIGHLIGHT_GREEN, | ||
BLUE, | ||
RED, | ||
HIGHLIGHT_OVERLAP | ||
|
||
# Includes rmhacks tools | ||
type RemarkableTool* = enum | ||
BRUSH, | ||
PENCIL, | ||
BALLPOINT, | ||
MARKER, | ||
FINELINER, | ||
HIGHLIGHTER, | ||
ERASER, | ||
MECHANICAL, | ||
ERASER_AREA, | ||
CALLIGRAPHY, | ||
UNKNOWN | ||
|
||
# This is used as the index LUT for the .lines files | ||
let pen_lut* = [BRUSH, PENCIL, BALLPOINT, MARKER, FINELINER, HIGHLIGHTER, ERASER, MECHANICAL, | ||
ERASER_AREA, UNKNOWN, UNKNOWN, UNKNOWN, BRUSH, MECHANICAL, PENCIL, BALLPOINT, MARKER, | ||
FINELINER, HIGHLIGHTER, ERASER, UNKNOWN, CALLIGRAPHY] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import nimPDF/nimPDF | ||
import ../lines | ||
|
||
# color is already set in stroke and fill color | ||
proc draw_fineliner*(x: Stroke, to: var PDF, scale: float) = | ||
to.saveState() | ||
|
||
# Values found by guesstimation | ||
to.setLineWidth(scale * 0.4) | ||
to.setLineCap(ROUND_END) | ||
to.setLineJoin(MITER_JOIN) | ||
to.setMiterLimit(1.0) | ||
to.moveTo(x.segments[0].x * SCALE_FACTOR, x.segments[0].y * SCALE_FACTOR) | ||
for i in 1..(x.segments.len - 1): | ||
let next = x.segments[i] | ||
to.lineTo(next.x * SCALE_FACTOR, next.y * SCALE_FACTOR) | ||
to.stroke() | ||
|
||
import nimPDF/nimPDF | ||
import ../lines | ||
|
||
# color is already set in stroke and fill color | ||
proc draw_fineliner*(x: Stroke, to: var PDF, scale: float) = | ||
to.saveState() | ||
|
||
# Values found by guesstimation | ||
to.setLineWidth(scale * 0.4) | ||
to.setLineCap(ROUND_END) | ||
to.setLineJoin(MITER_JOIN) | ||
to.setMiterLimit(1.0) | ||
to.moveTo(x.segments[0].x * SCALE_FACTOR, x.segments[0].y * SCALE_FACTOR) | ||
for i in 1..(x.segments.len - 1): | ||
let next = x.segments[i] | ||
to.lineTo(next.x * SCALE_FACTOR, next.y * SCALE_FACTOR) | ||
to.stroke() | ||
|
||
to.restoreState() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import nimPDF/nimPDF | ||
import ../lines | ||
|
||
# color is already set in stroke and fill color | ||
proc draw_highlighter*(x: Stroke, to: var PDF, scale: float) = | ||
to.saveState() | ||
|
||
# TODO: Doesn't quite match remarkable results | ||
to.setLineWidth(scale * 3.0) | ||
to.setLineCap(SQUARE_END) | ||
to.setLineJoin(BEVEL_JOIN) | ||
to.setAlpha(0.5) | ||
to.setBlendMode(BM_OVERLAY) | ||
to.moveTo(x.segments[0].x * SCALE_FACTOR, x.segments[0].y * SCALE_FACTOR) | ||
for i in 1..(x.segments.len - 1): | ||
let next = x.segments[i] | ||
to.lineTo(next.x * SCALE_FACTOR, next.y * SCALE_FACTOR) | ||
to.stroke() | ||
|
||
import nimPDF/nimPDF | ||
import ../lines | ||
|
||
# color is already set in stroke and fill color | ||
proc draw_highlighter*(x: Stroke, to: var PDF, scale: float) = | ||
to.saveState() | ||
|
||
# TODO: Doesn't quite match remarkable results | ||
to.setLineWidth(scale * 3.0) | ||
to.setLineCap(SQUARE_END) | ||
to.setLineJoin(BEVEL_JOIN) | ||
to.setAlpha(0.5) | ||
to.setBlendMode(BM_OVERLAY) | ||
to.moveTo(x.segments[0].x * SCALE_FACTOR, x.segments[0].y * SCALE_FACTOR) | ||
for i in 1..(x.segments.len - 1): | ||
let next = x.segments[i] | ||
to.lineTo(next.x * SCALE_FACTOR, next.y * SCALE_FACTOR) | ||
to.stroke() | ||
|
||
to.restoreState() |
Oops, something went wrong.