Skip to content

Commit

Permalink
improvements to console, multiline, bug fixes around dialects, os / p…
Browse files Browse the repository at this point in the history
…ipes contexts
  • Loading branch information
refaktor committed Sep 11, 2024
1 parent ce0712b commit 796d195
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 19 deletions.
2 changes: 1 addition & 1 deletion evaldo/builtins_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var Builtins_console = map[string]*env.Builtin{
}
}*/

DoRyeRepl(ps, "do", ShowResults)
DoRyeRepl(ps, "rye", ShowResults)
fmt.Println("-------------------------------------------------------------")
ps.Ser = ser
return ps.Res
Expand Down
6 changes: 3 additions & 3 deletions evaldo/builtins_os_not.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//go:build no_devops
// +build no_devops
//go:build no_os
// +build no_os

package evaldo

import (
"github.com/refaktor/rye/env"
)

var Builtins_devops = map[string]*env.Builtin{}
var Builtins_os = map[string]*env.Builtin{}
6 changes: 3 additions & 3 deletions evaldo/builtins_pipes_not.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//go:build no_devops
// +build no_devops
//go:build no_pipes
// +build no_pipes

package evaldo

import (
"github.com/refaktor/rye/env"
)

var Builtins_devops = map[string]*env.Builtin{}
var Builtins_os = map[string]*env.Builtin{}
40 changes: 30 additions & 10 deletions evaldo/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package evaldo
import (
"context"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
Expand All @@ -16,8 +15,6 @@ import (
"github.com/refaktor/rye/env"
"github.com/refaktor/rye/loader"
"github.com/refaktor/rye/util"

"github.com/refaktor/liner"
)

var (
Expand All @@ -33,7 +30,7 @@ type ShellEd struct {
Return env.Object
}

func genPrompt(shellEd *ShellEd, line string) (string, string) {
func genPrompt(shellEd *ShellEd, line string, multiline bool) (string, string) {
if shellEd != nil && shellEd.Mode != "" {
a := shellEd.Askfor
if len(a) > 0 {
Expand All @@ -49,7 +46,11 @@ func genPrompt(shellEd *ShellEd, line string) (string, string) {
if len(line) > 0 {
return " ", ""
} else {
return "×> ", ""
if multiline {
return " > ", ""
} else {
return "×> ", ""
}
}
}
}
Expand Down Expand Up @@ -210,6 +211,7 @@ func (r *Repl) evalLine(es *env.ProgramState, code string) string {
es.Dialect = env.EyrDialect
Eyr_EvalBlock(es, true)
} else if r.dialect == "math" {

idxx, _ := es.Idx.GetIndex("math")
s1, ok := es.Ctx.Get(idxx)
if ok {
Expand All @@ -229,6 +231,8 @@ func (r *Repl) evalLine(es *env.ProgramState, code string) string {
Eyr_EvalBlock(es, false)
es.Ser = ser
}
} else {
fmt.Println("Unknown dialect: " + r.dialect)
}

MaybeDisplayFailureOrError(es, genv)
Expand Down Expand Up @@ -294,6 +298,9 @@ func constructKeyEvent(r rune, k keyboard.Key) util.KeyEvent {
case keyboard.KeyCtrlU:
ch = "u"
ctrl = true
case keyboard.KeyCtrlX:
ch = "x"
ctrl = true

case keyboard.KeyEnter:
code = 13
Expand Down Expand Up @@ -383,6 +390,16 @@ func DoRyeRepl(es *env.ProgramState, dialect string, showResults bool) { // here
fmt.Println(err)
}
// fmt.Println("END")

// TODO -- make it save history
/* if f, err := os.Create(history_fn); err != nil {
log.Print("Error writing history file: ", err)
} else {
if _, err := line.WriteHistory(f); err != nil {
log.Print("Error writing history file: ", err)
}
f.Close()
}*/
}

/* THIS WAS DISABLED TEMP FOR WASM MODE .. 20250116 func DoGeneralInput(es *env.ProgramState, prompt string) {
Expand All @@ -406,7 +423,7 @@ func DoGeneralInputField(es *env.ProgramState, prompt string) {
}
*/

func DoRyeRepl_OLD(es *env.ProgramState, showResults bool) { // here because of some odd options we were experimentally adding
/* func DoRyeRepl_OLD(es *env.ProgramState, showResults bool) { // here because of some odd options we were experimentally adding
codestr := "a: 100\nb: \"jim\"\nprint 10 + 20 + b"
codelines := strings.Split(codestr, ",\n")
Expand Down Expand Up @@ -444,8 +461,10 @@ func DoRyeRepl_OLD(es *env.ProgramState, showResults bool) { // here because of
var prevResult env.Object
multiline := false
for {
prompt, arg := genPrompt(&shellEd, line2)
prompt, arg := genPrompt(&shellEd, line2, multiline)
if code, err := line.Prompt(prompt); err == nil {
// strip comment
Expand All @@ -459,7 +478,7 @@ func DoRyeRepl_OLD(es *env.ProgramState, showResults bool) { // here because of
es.LiveObj.ClearUpdates()
es.LiveObj.PsMutex.Unlock()
multiline := len(code) > 1 && code[len(code)-1:] == " "
multiline = len(code) > 1 && code[len(code)-1:] == " "
comment := regexp.MustCompile(`\s*;`)
line1 := comment.Split(code, 2) //--- just very temporary solution for some comments in repl. Later should probably be part of loader ... maybe?
Expand Down Expand Up @@ -550,14 +569,14 @@ func DoRyeRepl_OLD(es *env.ProgramState, showResults bool) { // here because of
for _, c := range codelines {
fmt.Println(c)
}
MoveCursorUp(len(codelines))*/
MoveCursorUp(len(codelines)) * /
} else {
log.Print("Error reading line: ", err)
break
}
}
if f, err := os.Create(history_fn); err != nil {
if f, err := os.Create(history_fn); err != nil {
log.Print("Error writing history file: ", err)
} else {
if _, err := line.WriteHistory(f); err != nil {
Expand All @@ -566,3 +585,4 @@ func DoRyeRepl_OLD(es *env.ProgramState, showResults bool) { // here because of
f.Close()
}
}
*/
Binary file added examples/os_pipes/main.db
Binary file not shown.
13 changes: 13 additions & 0 deletions examples/os_pipes/make_num_dirs.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;
;
;


cc os cc pipes ; temporary ... make a command to combine contexts and do code in that

; GOAL:
; create folders with numbers 1 to 20
; in odd numbered folders create files odd
; in even numbered folders create sqlite databases with one table


4 changes: 2 additions & 2 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func main_rye_file(file string, sig bool, subc bool, interactive bool, code stri
evaldo.MaybeDisplayFailureOrError(ps, ps.Idx)

if interactive {
evaldo.DoRyeRepl(ps, "do", evaldo.ShowResults)
evaldo.DoRyeRepl(ps, "rye", evaldo.ShowResults)
}

case env.Error:
Expand Down Expand Up @@ -449,7 +449,7 @@ func main_rye_file_OLD(file string, sig bool, subc bool, interactive bool, code
evaldo.MaybeDisplayFailureOrError(es, genv)

if interactive {
evaldo.DoRyeRepl(es, "do", evaldo.ShowResults)
evaldo.DoRyeRepl(es, "rye", evaldo.ShowResults)
}

case env.Error:
Expand Down
20 changes: 20 additions & 0 deletions util/microliner.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,28 @@ startOfHere:
len(p)+len(line) < s.columns*4 && // Avoid countGlyphs on large lines
countGlyphs(p)+countGlyphs(line) < s.columns-1 {*/
///// pLen := countGlyphs(p)

if next.Ctrl {
switch strings.ToLower(next.Key) {
case "x":
// TEMP copy of code below ... refactor
historyStale = true
s.lastLineString = false
// trace2("NL")
s.sendBack(fmt.Sprintf("%s⏎\n%s", color_emph, reset))
if s.inString {
s.lastLineString = true
}
s.enterLine(string(line) + " ")
pos = 0
//if xx == "next line" {
multiline = true
//} else {
// s.sendBack("") // WW?
//}
line = make([]rune, 0)
trace(line)
goto startOfHere
case "c":
/* return "", ErrPromptAborted
line = line[:0]
Expand Down

0 comments on commit 796d195

Please sign in to comment.