Skip to content

Commit

Permalink
switch to ergochat/readline, enable readline by default (#41)
Browse files Browse the repository at this point in the history
* switch to ergochat/readline, enable readline by default

* don't shadow the console library

* bump readline to v0.0.3

* bump readline temporarily to 2f9fbc2eecc78

* fetch the new readline tag
  • Loading branch information
slingamn authored Jun 2, 2023
1 parent b7bd084 commit b743eda
Show file tree
Hide file tree
Showing 159 changed files with 12,980 additions and 4,261 deletions.
6 changes: 4 additions & 2 deletions lib/console.go → console/console.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) 2023 Shivaram Lingamneni <[email protected]>
// released under the ISC license

package lib
package console

import (
"io"
"os"

"github.com/ergochat/irc-go/ircreader"

"github.com/ergochat/ircdog/lib"
)

// Console is an abstract representation of keyboard input and screen output
Expand All @@ -26,7 +28,7 @@ type stdioConsole struct {

func NewStandardConsole() (Console, error) {
result := new(stdioConsole)
result.reader.Initialize(os.Stdin, InitialBufferSize, MaxBufferSize)
result.reader.Initialize(os.Stdin, lib.InitialBufferSize, lib.MaxBufferSize)
return result, nil
}

Expand Down
7 changes: 7 additions & 0 deletions console/minimal_stubs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build minimal

package console

func NewConsole(enableReadline bool, historyFile string) (Console, error) {
return NewStandardConsole()
}
21 changes: 21 additions & 0 deletions console/readline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !minimal

package console

import (
"syscall"

"github.com/ergochat/readline"
"golang.org/x/term"
)

func NewConsole(enableReadline bool, historyFile string) (Console, error) {
if !(enableReadline && term.IsTerminal(int(syscall.Stdin))) {
return NewStandardConsole()
}
return readline.NewFromConfig(&readline.Config{
Prompt: ">>> ",
HistoryFile: historyFile,
HistoryLimit: 1000,
})
}
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ module github.com/ergochat/ircdog
go 1.19

require (
github.com/chzyer/readline v1.5.1
github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536
github.com/ergochat/irc-go v0.3.0
github.com/ergochat/readline v0.0.4
github.com/gorilla/websocket v1.5.0
github.com/jwalton/go-supportscolor v1.1.0
golang.org/x/term v0.6.0
)

require (
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.3.7 // indirect
)

replace github.com/chzyer/readline => github.com/slingamn/readline v0.0.0-20230227035143-99fd32183842
19 changes: 12 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536 h1:rHnpq7uNlix5l7tWZ55iJcHHrxCPnOVF4FGb7qOT2Jc=
github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/ergochat/irc-go v0.3.0 h1:qgvb2knh8d6yIVsHX+PRQ2CiRj1NGG5x88ABmR1lWng=
github.com/ergochat/irc-go v0.3.0/go.mod h1:2vi7KNpIPWnReB5hmLpl92eMywQvuIeIIGdt/FQCph0=
github.com/ergochat/readline v0.0.2 h1:AlCbi98PNX4fxvduMrEbf72jRjHCTnFCSOpx4OhJnGE=
github.com/ergochat/readline v0.0.2/go.mod h1:9g3OwkSE7gXLVkbd1LpZS/tuOCtO3oGezyxp/fJwUx8=
github.com/ergochat/readline v0.0.3 h1:PYU6ItEq7JW4QLZmR8y4f2kGqWUyJtQdrucK4c/C9wg=
github.com/ergochat/readline v0.0.3/go.mod h1:9g3OwkSE7gXLVkbd1LpZS/tuOCtO3oGezyxp/fJwUx8=
github.com/ergochat/readline v0.0.4 h1:NvLFqh4iBaGZNu9J1hZHQnme/WKH8Jiew+u3CwA/Igw=
github.com/ergochat/readline v0.0.4/go.mod h1:9g3OwkSE7gXLVkbd1LpZS/tuOCtO3oGezyxp/fJwUx8=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jwalton/go-supportscolor v1.1.0 h1:HsXFJdMPjRUAx8cIW6g30hVSFYaxh9yRQwEWgkAR7lQ=
github.com/jwalton/go-supportscolor v1.1.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
github.com/slingamn/readline v0.0.0-20230227035143-99fd32183842 h1:dZinPfCSSyz4UhEHJbftBTMShexVSP9ecKfoahYHr/o=
github.com/slingamn/readline v0.0.0-20230227035143-99fd32183842/go.mod h1:6vWnQ7ytBpt1mO7e1J5f0U5Dr9uGRUFMMQn6K/VOVis=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
26 changes: 7 additions & 19 deletions ircdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/ergochat/irc-go/ircfmt"
"github.com/ergochat/irc-go/ircmsg"

libconsole "github.com/ergochat/ircdog/console"
"github.com/ergochat/ircdog/lib"
"github.com/ergochat/ircdog/readline"
)

// set via linker flags, either by make or by goreleaser:
Expand Down Expand Up @@ -79,7 +79,7 @@ Options:
https://pkg.go.dev/github.com/goshuirc/irc-go/ircfmt
--italics Enable ANSI italics codes (not widely supported).
--color=<mode> Override detected color support ('none', '16', '256').
--readline Enable experimental readline support.
--no-readline Disable readline support.
--script=<file> Read an initial list of commands to send from a file.
--reconnect=<time> If disconnected unexpectedly, reconnect after a pause
('30' for 30 seconds, '5m' for 5 minutes, etc.)
Expand Down Expand Up @@ -274,13 +274,7 @@ func main() {
colorLevel := determineColorLevel(arguments["--color"])

verbose := arguments["--verbose"].(bool)
enableReadline := arguments["--readline"].(bool)
if raw && enableReadline {
log.Fatal("Cannot enable readline support with --raw")
}
if !raw && os.Getenv("IRCDOG_READLINE") == "1" {
enableReadline = true
}
disableReadline := arguments["--no-readline"].(bool) || os.Getenv("IRCDOG_READLINE") == "0"

var transcript *lib.Transcript
if transcriptFile := arguments["--transcript"]; transcriptFile != nil {
Expand All @@ -307,7 +301,7 @@ func main() {
exitStatus = runClient(
connectionConfig, hiddenCommands, transcript,
raw, escape, answerPings, useItalics, colorLevel,
verbose, enableReadline, script, reconnectDuration,
verbose, disableReadline, script, reconnectDuration,
)
} else {
exitStatus = runListenProxy(
Expand All @@ -322,14 +316,8 @@ func runClient(
connectionConfig lib.ConnectionConfig,
hiddenCommands map[string]bool, transcript *lib.Transcript,
raw, escape, answerPings, useItalics bool, colorLevel lib.ColorLevel,
verbose, enableReadline bool, script string, reconnectDuration time.Duration) int {
var console lib.Console
var err error
if !raw && enableReadline {
console, err = readline.NewReadline(os.Getenv("IRCDOG_HISTFILE"))
} else {
console, err = lib.NewStandardConsole()
}
verbose, disableReadline bool, script string, reconnectDuration time.Duration) int {
console, err := libconsole.NewConsole(!(raw || disableReadline), os.Getenv("IRCDOG_HISTFILE"))
if err != nil {
log.Printf("** ircdog could not initialize console: %s\n", err.Error())
return 1
Expand Down Expand Up @@ -370,7 +358,7 @@ func runClient(
}

func connectExternal(
console lib.Console, lineChan chan string, connectionConfig lib.ConnectionConfig,
console libconsole.Console, lineChan chan string, connectionConfig lib.ConnectionConfig,
hiddenCommands map[string]bool, transcript *lib.Transcript,
raw, escape, answerPings, useItalics bool, colorLevel lib.ColorLevel,
verbose bool, script string) (status int) {
Expand Down
13 changes: 0 additions & 13 deletions readline/minimal_stubs.go

This file was deleted.

17 changes: 0 additions & 17 deletions readline/readline.go

This file was deleted.

Loading

0 comments on commit b743eda

Please sign in to comment.