From 8ec394a4df5e5bb220bb2e1379781da5c6e707cc Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Tue, 25 Jul 2017 18:48:41 +0000 Subject: [PATCH] Adding plan9 raw mode --- config.go | 35 +++++++++++++++++++++++++++++++++-- helper.go | 8 -------- main.go | 3 --- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/config.go b/config.go index 4a4adb580de596dfe302d1115a9a3a5226c7206a..10e5b167bcb22284130471f608946ea4fe08541b 100644 --- a/config.go +++ b/config.go @@ -8,7 +8,7 @@ import ( "os" "os/user" - "golang.org/x/crypto/ssh/terminal" +// "golang.org/x/crypto/ssh/terminal" ) //Configuration is a struct that contains all configuration fields @@ -64,7 +64,38 @@ func CreateConfig() { EmptyStruct.Username = scan.Text() fmt.Println("Input your password") - password, err := terminal.ReadPassword(0) + //password, err := terminal.ReadPassword(0) + + plan9 := true + /* Plan 9 raw mode for rio */ + consctl, err := os.Open("/dev/consctl") + if err != nil { + /* not on Plan 9 */ + plan9 = false + } + + password := ""; + + if plan9 { + rawon := make([]byte, 5) + rawon = []byte("rawon") + _, err = consctl.Write(rawon) + if err != nil { + fmt.Println("Failed to set rawon") + } else { + cons, err := os.Open("/dev/cons") + scan := bufio.NewScanner(cons) + scan.Scan() + password = scan.Text() + rawoff := make([]byte, 6) + rawoff = []byte("rawoff") + _, err = consctl.Write(rawoff) + if err != nil { + fmt.Println("Failed to set rawoff") + } + } + } + EmptyStruct.Password = string(password) EmptyStruct.Messages = 10 EmptyStruct.MessageDefault = true diff --git a/helper.go b/helper.go index 10838ebce7fff5abc4ea6d2037a17e1b31ed11da..5a5a8bf3ea8656e6d8927f2506c1696eef89d3ec 100644 --- a/helper.go +++ b/helper.go @@ -2,7 +2,6 @@ package main import ( "log" - "os" "os/exec" "strings" "time" @@ -22,13 +21,6 @@ func Msg(MsgType, format string, a ...interface{}) { fmt.Printf(format, a...) } -//Clear clears the terminal => This barely works, please fix → Nope -func Clear() { - c := exec.Command("clear") - c.Stdout = os.Stdout - c.Run() -} - //Header simply prints a header containing state/session information func Header() { Msg(InfoMsg, "Welcome, %s!\n\n", State.Session.User.Username) diff --git a/main.go b/main.go index 749f6740f4f78ce90ca2c8904c7e59cca43f6a48..6acec14b18fc50975fbcd1cbdaca51f0f7bc06cd 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,6 @@ func main() { //Initialize Config GetConfig() CheckState() - Clear() Msg(HeaderMsg, "disco version: %s\n\n", Version) //NewSession @@ -97,7 +96,6 @@ func InitWindow() { //ShowContent shows defaulth Channel content func ShowContent() { - Clear() Header() if Config.MessageDefault { State.RetrieveMessages(Config.Messages) @@ -107,7 +105,6 @@ func ShowContent() { //ShowEmptyContent shows an empty channel func ShowEmptyContent() { - Clear() Header() }