Compare commits

...

2 Commits

4 changed files with 26 additions and 11 deletions

View File

@ -1,5 +1,9 @@
# 🎀 Changelog # 🎀 Changelog
## Unreleased
### Added
- `cat` command now reads files in chunks, allowing for reading large files
## [2.2.2] - 2024-04-16 ## [2.2.2] - 2024-04-16
### Fixed ### Fixed
- Line refresh fixes (less flicker) - Line refresh fixes (less flicker)

11
api.go
View File

@ -712,5 +712,14 @@ func hlhinter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// #example // #example
// #param line string // #param line string
func hlhighlighter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlhighlighter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil if err := c.Check1Arg(); err != nil {
return nil, err
}
line, err := c.StringArg(0)
if err != nil {
return nil, err
}
return c.PushingNext1(t.Runtime, rt.StringValue(line)), nil
} }

View File

@ -9,6 +9,8 @@ commander.register('cat', function(args, sinks)
usage: cat [file]...]] usage: cat [file]...]]
end end
local chunk_size = 2^13 -- 8K buffer size
for _, fName in ipairs(args) do for _, fName in ipairs(args) do
local f = io.open(fName) local f = io.open(fName)
if f == nil then if f == nil then
@ -17,7 +19,12 @@ usage: cat [file]...]]
goto continue goto continue
end end
sinks.out:writeln(f:read '*a') while true do
local block = f:read(chunk_size)
if not block then break end
sinks.out:write(block)
end
sinks.out:writeln("")
::continue:: ::continue::
end end
io.flush() io.flush()

13
rl.go
View File

@ -70,11 +70,8 @@ func newLineReader(prompt string, noHist bool) *lineReader {
hooks.Emit("hilbish.vimAction", actionStr, args) hooks.Emit("hilbish.vimAction", actionStr, args)
} }
rl.HintText = func(line []rune, pos int) []rune { rl.HintText = func(line []rune, pos int) []rune {
if hinter == nil { hinter := hshMod.Get(rt.StringValue("hinter"))
return []rune{} retVal, err := rt.Call1(l.MainThread(), hinter,
}
retVal, err := rt.Call1(l.MainThread(), rt.FunctionValue(hinter),
rt.StringValue(string(line)), rt.IntValue(int64(pos))) rt.StringValue(string(line)), rt.IntValue(int64(pos)))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -89,10 +86,8 @@ func newLineReader(prompt string, noHist bool) *lineReader {
return []rune(hintText) return []rune(hintText)
} }
rl.SyntaxHighlighter = func(line []rune) string { rl.SyntaxHighlighter = func(line []rune) string {
if highlighter == nil { highlighter := hshMod.Get(rt.StringValue("highlighter"))
return string(line) retVal, err := rt.Call1(l.MainThread(), highlighter,
}
retVal, err := rt.Call1(l.MainThread(), rt.FunctionValue(highlighter),
rt.StringValue(string(line))) rt.StringValue(string(line)))
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)