From 5c6310b1ca7bdfce23dfcffc00fedee355a35a03 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 6 Dec 2021 17:21:31 -0400 Subject: [PATCH] refactor: dont export functions and types --- hilbish.go | 4 ++-- lua.go | 6 +++--- main.go | 27 +++++++++++++-------------- rl.go | 16 ++++++++-------- rl_hilbiline.go | 16 ++++++++-------- shell.go | 4 ++-- 6 files changed, 36 insertions(+), 37 deletions(-) diff --git a/hilbish.go b/hilbish.go index 2555c6b..21460e6 100644 --- a/hilbish.go +++ b/hilbish.go @@ -22,7 +22,7 @@ var exports = map[string]lua.LGFunction { "read": hlread, } -func HilbishLoader(L *lua.LState) int { +func hilbishLoader(L *lua.LState) int { mod := L.SetFuncs(L.NewTable(), exports) host, _ := os.Hostname() @@ -103,7 +103,7 @@ func getenv(key, fallback string) string { // Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen) func hlread(L *lua.LState) int { luaprompt := L.CheckString(1) - lualr := NewLineReader(luaprompt) + lualr := newLineReader(luaprompt) input, err := lualr.Read() if err != nil { diff --git a/lua.go b/lua.go index f166872..13ff60e 100644 --- a/lua.go +++ b/lua.go @@ -34,7 +34,7 @@ func LuaInit() { l.SetGlobal("interval", l.NewFunction(hshinterval)) // yes this is stupid, i know - l.PreloadModule("hilbish", HilbishLoader) + l.PreloadModule("hilbish", hilbishLoader) l.DoString("hilbish = require 'hilbish'") // Add fs and terminal module module to Lua @@ -75,7 +75,7 @@ func LuaInit() { } } } -func RunConfig(confpath string) { +func runConfig(confpath string) { if !interactive { return } @@ -88,7 +88,7 @@ func RunConfig(confpath string) { } } -func RunLogin() { +func runLogin() { if _, err := os.Stat(curuser.HomeDir + "/.hprofile.lua"); os.IsNotExist(err) { return } diff --git a/main.go b/main.go index 11113a3..1262be4 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( var ( l *lua.LState - lr *LineReader + lr *lineReader commands = map[string]*lua.LFunction{} aliases = map[string]string{} @@ -138,20 +138,20 @@ func main() { } } - go HandleSignals() + go handleSignals() LuaInit() - RunLogin() - RunConfig(*configflag) + runLogin() + runConfig(*configflag) if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 { scanner := bufio.NewScanner(bufio.NewReader(os.Stdin)) for scanner.Scan() { - RunInput(scanner.Text()) + runInput(scanner.Text()) } } if *cmdflag != "" { - RunInput(*cmdflag) + runInput(*cmdflag) } if getopt.NArgs() > 0 { @@ -169,7 +169,7 @@ func main() { os.Exit(0) } - lr = NewLineReader("") + lr = newLineReader("") input: for interactive { running = false @@ -194,7 +194,7 @@ input: if strings.HasSuffix(input, "\\") { for { - input, err = ContinuePrompt(strings.TrimSuffix(input, "\\")) + input, err = continuePrompt(strings.TrimSuffix(input, "\\")) if err != nil { goto input // continue inside nested loop } @@ -203,8 +203,8 @@ input: } } } - HandleHistory(input) - RunInput(input) + handleHistory(input) + runInput(input) termwidth, _, err := term.GetSize(0) if err != nil { @@ -214,7 +214,7 @@ input: } } -func ContinuePrompt(prev string) (string, error) { +func continuePrompt(prev string) (string, error) { hooks.Em.Emit("multiline", nil) lr.SetPrompt(multilinePrompt) cont, err := lr.Read() @@ -259,8 +259,7 @@ func fmtPrompt() string { return nprompt } -// do i even have to say -func HandleSignals() { +func handleSignals() { c := make(chan os.Signal) signal.Notify(c, os.Interrupt, syscall.SIGWINCH) @@ -280,7 +279,7 @@ func HandleSignals() { } } -func HandleHistory(cmd string) { +func handleHistory(cmd string) { lr.AddHistory(cmd) // TODO: load history again (history shared between sessions like this ye) } diff --git a/rl.go b/rl.go index 4926ea2..c8cf4c2 100644 --- a/rl.go +++ b/rl.go @@ -16,11 +16,11 @@ import ( "github.com/yuin/gopher-lua" ) -type LineReader struct { +type lineReader struct { Prompt string } -func NewLineReader(prompt string) *LineReader { +func newLineReader(prompt string) *lineReader { readline.Init() readline.Completer = func(query string, ctx string) []string { @@ -154,30 +154,30 @@ func NewLineReader(prompt string) *LineReader { } readline.LoadHistory(defaultHistPath) - return &LineReader{ + return &lineReader{ Prompt: prompt, } } -func (lr *LineReader) Read() (string, error) { +func (lr *lineReader) Read() (string, error) { hooks.Em.Emit("command.precmd", nil) return readline.String(lr.Prompt) } -func (lr *LineReader) SetPrompt(prompt string) { +func (lr *lineReader) SetPrompt(prompt string) { lr.Prompt = prompt } -func (lr *LineReader) AddHistory(cmd string) { +func (lr *lineReader) AddHistory(cmd string) { readline.AddHistory(cmd) readline.SaveHistory(defaultHistPath) } -func (lr *LineReader) ClearInput() { +func (lr *lineReader) ClearInput() { readline.ReplaceLine("", 0) readline.RefreshLine() } -func (lr *LineReader) Resize() { +func (lr *lineReader) Resize() { readline.Resize() } diff --git a/rl_hilbiline.go b/rl_hilbiline.go index 68d4745..6f872c5 100644 --- a/rl_hilbiline.go +++ b/rl_hilbiline.go @@ -8,36 +8,36 @@ package main import "github.com/Rosettea/Hilbiline" -type LineReader struct { +type lineReader struct { hl *hilbiline.HilbilineState } // other gophers might hate this naming but this is local, shut up -func NewLineReader(prompt string) *LineReader { +func newLineReader(prompt string) *lineReader { hl := hilbiline.New(prompt) - return &LineReader{ + return &lineReader{ &hl, } } -func (lr *LineReader) Read() (string, error) { +func (lr *lineReader) Read() (string, error) { return lr.hl.Read() } -func (lr *LineReader) SetPrompt(prompt string) { +func (lr *lineReader) SetPrompt(prompt string) { lr.hl.SetPrompt(prompt) } -func (lr *LineReader) AddHistory(cmd string) { +func (lr *lineReader) AddHistory(cmd string) { return } -func (lr *LineReader) ClearInput() { +func (lr *lineReader) ClearInput() { return } -func (lr *LineReader) Resize() { +func (lr *lineReader) Resize() { return } diff --git a/shell.go b/shell.go index cae6c23..798a1bd 100644 --- a/shell.go +++ b/shell.go @@ -14,7 +14,7 @@ import ( "mvdan.cc/sh/v3/syntax" ) -func RunInput(input string) { +func runInput(input string) { running = true cmdArgs, cmdString := splitInput(input) @@ -61,7 +61,7 @@ func RunInput(input string) { // If input is incomplete, start multiline prompting if syntax.IsIncomplete(err) { for { - cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\")) + cmdString, err = continuePrompt(strings.TrimSuffix(cmdString, "\\")) if err != nil { break }