refactor: dont export functions and types

dev
TorchedSammy 2021-12-06 17:21:31 -04:00
parent 369ddcc100
commit 5c6310b1ca
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
6 changed files with 36 additions and 37 deletions

View File

@ -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 {

6
lua.go
View File

@ -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
}

27
main.go
View File

@ -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)
}

16
rl.go
View File

@ -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()
}

View File

@ -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
}

View File

@ -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
}