Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go tooling and documentation #70

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
8177a46
spike docs
CrowdHailer Apr 29, 2023
7b3b948
a load more styling
CrowdHailer Apr 30, 2023
d3f0faa
quick fix
CrowdHailer May 1, 2023
26f0d6f
working on a variety of stuff
CrowdHailer May 1, 2023
9f7b856
thoughts
CrowdHailer May 1, 2023
b2b4b5a
close all the tabs
CrowdHailer May 2, 2023
f63f97d
start go editing
CrowdHailer May 7, 2023
80f550e
use countable index on position
CrowdHailer May 7, 2023
deaef01
add index based counting
CrowdHailer May 7, 2023
c01b7c6
handle reaching the edge
CrowdHailer May 8, 2023
f2f72a2
add cursor to go implementation
CrowdHailer May 8, 2023
2ebbb81
add list
CrowdHailer May 8, 2023
3ad6ab9
spike list stuff
CrowdHailer May 8, 2023
41fcb1d
flatten list render
CrowdHailer May 9, 2023
7bf58fb
assignment and var
CrowdHailer May 9, 2023
181ca84
add remaining node
CrowdHailer May 9, 2023
5639e0b
write color
CrowdHailer May 9, 2023
b2f31b0
collect all render code
CrowdHailer May 9, 2023
7b9e109
add tag and reord
CrowdHailer May 9, 2023
ae108da
track selected
CrowdHailer May 9, 2023
1c722e2
focus on selected and update text
CrowdHailer May 9, 2023
f6e39b1
add call delete
CrowdHailer May 9, 2023
1615d7f
editing a string
CrowdHailer May 9, 2023
d6e2338
render records
CrowdHailer May 9, 2023
0dcf39e
fix multiline let
CrowdHailer May 9, 2023
110562c
notes
CrowdHailer May 9, 2023
91aa035
encode to JSON
CrowdHailer May 9, 2023
d308b3b
implement encodig
CrowdHailer May 10, 2023
e78ce80
save and load interface
CrowdHailer May 10, 2023
25d1eea
implement copy paste
CrowdHailer May 10, 2023
69827c7
overwrite and perform
CrowdHailer May 10, 2023
eb7e471
implement function and select
CrowdHailer May 10, 2023
d7a4daa
comment
CrowdHailer May 10, 2023
281a891
lots of ideas
CrowdHailer May 12, 2023
10470c5
rest of changes
CrowdHailer May 12, 2023
ab85baf
another approach scribbled down
CrowdHailer May 12, 2023
2132faa
test printing nodes
CrowdHailer May 13, 2023
ef86abd
trying to do lists
CrowdHailer May 13, 2023
6dd09b5
print rest of the list
CrowdHailer May 14, 2023
fc4f96f
failing nested test
CrowdHailer May 14, 2023
4ed5ebd
fix overflow
CrowdHailer May 14, 2023
881cad0
fix overflow
CrowdHailer May 14, 2023
2ad0f8c
spelling mistake
CrowdHailer May 14, 2023
3fc9815
spike record
CrowdHailer May 14, 2023
beb7306
some useful ish cleanup
CrowdHailer May 14, 2023
8931ec8
connect editor 2
CrowdHailer May 15, 2023
7992fe1
add backspace functionality
CrowdHailer May 15, 2023
53f56c5
lots of small cleanup
CrowdHailer May 15, 2023
9251ad8
new styles for effects
CrowdHailer May 15, 2023
2dbe4c9
negative numbers
CrowdHailer May 15, 2023
d742e97
perform label keypress
CrowdHailer May 15, 2023
bc7d9a9
spike handling case
CrowdHailer May 15, 2023
5b24be3
many more bugs
CrowdHailer May 16, 2023
b6dfb07
add info bar to the page
CrowdHailer May 16, 2023
0372fde
clean up todos
CrowdHailer May 16, 2023
66d8fab
add click;
CrowdHailer May 16, 2023
349754c
start with gleam text editor
CrowdHailer May 18, 2023
1a9c9d5
more efforts on a gleam editor
CrowdHailer May 19, 2023
22e3d59
fix placing cursor
CrowdHailer May 20, 2023
7b0f3b9
handle inserting text
CrowdHailer May 20, 2023
f7aa5da
fix deleting text
CrowdHailer May 20, 2023
f1098b5
render functions
CrowdHailer May 20, 2023
d8bca25
print block
CrowdHailer May 20, 2023
31e8b67
print remaining nodes
CrowdHailer May 20, 2023
41a41f9
solve cursor at end position
CrowdHailer May 21, 2023
51a91b8
fix typing in numbers
CrowdHailer May 21, 2023
698e09d
set up command mode
CrowdHailer May 21, 2023
467d91f
create negative numbers
CrowdHailer May 21, 2023
51360be
Merge branch 'main' into docs
CrowdHailer May 21, 2023
ba06820
Merge branch 'main' into docs
CrowdHailer May 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions fern/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
```
docker run -it -w /app -v ./fern:/app golang:1.20.4 bash
```

render text
then scroll overflow


Add before as a function in all blocks

let foo = a b ->
delete all of a label leaves red mark

delete arg

let foo = _ y -> {
let fdd = 2
let y = 11
}

" -> string
p -> perform
handle -> handle
{ -> record
l -> let
Enter Shift line above below
[ -> list
, -> list item
m -> match {
Red missing

}

No special key for Tag yet
letters for things means no typing for variables
automatically assume typing for variables can have selection along bottom by number but then number cant strt aa number
https://earthly.dev/blog/tui-app-with-go/

delete on let removes line highlight first
54 changes: 54 additions & 0 deletions fern/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/gdamore/tcell/v2"
"github.com/midas-framework/project_wisdom/fern"
)

func main() {
tcell.SetEncodingFallback(tcell.EncodingFallbackASCII)
screen, err := tcell.NewScreen()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if err = screen.Init(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}

dir, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
path := filepath.Join(dir, "saved.json")
// path := filepath.Join(dir, "../eyg/saved/saved.json")
store := &fileStore{path}

// fern.New(screen, store)
err = fern.Run(screen, store)
screen.Fini()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}

type fileStore struct {
path string
}

var _ fern.Store = (*fileStore)(nil)

func (store *fileStore) Load() ([]byte, error) {
return os.ReadFile(store.path)
}

func (store *fileStore) Save(data []byte) error {
return os.WriteFile(store.path, data, 0644)
}
8 changes: 8 additions & 0 deletions fern/coordinate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fern

// public fields because .X & .Y are useful interfactes to a point
// Technically Coordinate is 1D but we use singular here to save plural for lists
type Coordinate struct {
X int
Y int
}
62 changes: 62 additions & 0 deletions fern/cursor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package fern

func zipper(source Node, path []int) (Node, func(Node) Node, error) {
tree := source
var bs []func(Node) Node
for _, p := range path {
t, b, err := tree.child(p)
tree = t
if err != nil {
return Var{}, nil, err
}
bs = append(bs, b)
}
return tree, func(n Node) Node {
for i := len(bs) - 1; i >= 0; i-- {
n = bs[i](n)
}
return n
}, nil
}

// (call, (call, cons, x), tail)
// ((cons x) tail)
// (reverse (uppercase "bob"))
// ((map users) uppercase)

// x -> pre on list
// default is 5 -> [5] but also [1, 2] -> [1, [2]]
// always add to list

// making my own gc
// fast list of parents possible
// func z(source []string, remaining int) {
// root := source[0]
// }

// func unwrap(source []string, at int) {
// var parents = []string{}
// parent = parents[at]
// i := 0
// new := []string{}
// for i := 0; i < parent; i++ {
// new = append(new, source[i])
// }
// for i := at; i < len(source); i++ {
// new = append(new, source[i])
// }
// return new[12]
// }

// func callWith(source []string, at int) [2]int {
// // can have arrays for performance
// new := []string{}
// for i := 0; i < at; i++ {
// new = append(new, source[i])
// }
// new = append(new, "call", "vacant")
// for i := at; i < len(source); i++ {
// new = append(new, source[i])
// }

// }
98 changes: 98 additions & 0 deletions fern/decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package fern

import (
"encoding/json"
"fmt"
)

type encoded struct {
Key string `json:"0"`
Label string `json:"l"`
Body json.RawMessage `json:"b"`
Fn json.RawMessage `json:"f"`
Arg json.RawMessage `json:"a"`
// Let, Integer, String all have value
Value json.RawMessage `json:"v"`
Then json.RawMessage `json:"t"`
Note string `json:"c"`
}

// recursive, is continuation for looping a good style in go or is it just a hammer
func decode(data []byte) (Node, error) {
var e encoded
err := json.Unmarshal(data, &e)
if err != nil {
return nil, err
}
switch e.Key {
case "f":
body, err := decode(e.Body)
if err != nil {
return nil, err
}
return Fn{e.Label, body}, nil
case "a":
fn, err := decode(e.Fn)
if err != nil {
return nil, err
}
arg, err := decode(e.Arg)
if err != nil {
return nil, err
}
return Call{fn, arg}, nil
case "v":
return Var{e.Label}, nil
case "l":
value, err := decode(e.Value)
if err != nil {
return nil, err
}
then, err := decode(e.Then)
if err != nil {
return nil, err
}
return Let{e.Label, value, then}, nil
case "z":
return Vacant{e.Note}, nil
case "i":
var value int
err := json.Unmarshal(e.Value, &value)
if err != nil {
return nil, err
}
return Integer{value}, nil
case "s":
var value string
err := json.Unmarshal(e.Value, &value)
if err != nil {
return nil, err
}
return String{value}, nil
case "ta":
return Tail{}, nil
case "c":
return Cons{}, nil
case "u":
return Empty{}, nil
case "e":
return Extend{e.Label}, nil
case "g":
return Select{e.Label}, nil
case "o":
return Overwrite{e.Label}, nil
case "t":
return Tag{e.Label}, nil
case "m":
return Case{e.Label}, nil
case "n":
return NoCases{}, nil
case "p":
return Perform{e.Label}, nil
case "h":
return Handle{e.Label}, nil
case "b":
return Builtin{e.Label}, nil
}
return nil, fmt.Errorf("unknown node type %s", e.Key)
}
64 changes: 64 additions & 0 deletions fern/e2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package fern

// context i.e. context free grammer
// situation, surroundings
// location
// site
// position as in tail position

// ident path mode all needed, (block list)(sugar) also
// linear iteration a real pain for call

// linear walk through level on a line depth = new line and reduce ident
// pass in *path if there render return cursor
// dont pass in cursor if we delete from offset position that indicates selecting the node move to selected and path
// if we delete use path for new cursor
// arrow keys or escape exit

type situ struct {
indent int
nested bool
block bool
path []int
}

// state with count, output, and mapping to info
// len(info = count)
// separate focus from highlight
// func (string_ String) render(situ situ, focus []int, output []rendered) ([]rendered, []string) {
// // make a new pusher with offset counter inside
// zero := 0
// output = append(output, rendered{charachter: '"', offset: &zero})
// // start := len(output)
// // if targeted(focus) {
// // }
// for i, ch := range string_.value {
// offset := i + 1
// output = append(output, rendered{charachter: ch, offset: &offset})
// }
// output = append(output, rendered{charachter: '"'})
// if !situ.nested {
// output = append(output, rendered{charachter: '\n'})
// }
// // start := len(output)

// return nil, nil
// }

// y = count newlines
// x = count back to newline

func inner(focus []int, child int) []int {
// catches focus nil I believe
if len(focus) == 0 || focus[0] != child {
return nil
}
return focus[1:]
}

func targeted(focus []int) bool {
if focus != nil || len(focus) == 0 {
return true
}
return false
}
Loading