-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add CRWriter to add \r needed in raw mode automatically and efficiently #1
Conversation
ldemailly
commented
Aug 7, 2024
•
edited
Loading
edited
- move from grol.io/terminal
- add CRWriter to add \r
- add library CI
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
log.Infof("EOF received, exiting.") | ||
return 0 | ||
} | ||
return log.FErrf("Error reading line: %v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easier to read and understand
if err != nil { | |
if errors.Is(err, io.EOF) { | |
log.Infof("EOF received, exiting.") | |
return 0 | |
} | |
return log.FErrf("Error reading line: %v", err) | |
} | |
if errors.Is(err, io.EOF) { | |
log.Infof("EOF received, exiting.") | |
return 0 | |
} | |
if err != nil { | |
return log.FErrf("Error reading line: %v", err) | |
} |
} | ||
|
||
// CRWriter is a writer that adds \r before each \n. | ||
// Needed for raw mode terminals (and I guess also if you want something DOS or http headers like). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Needed for raw mode terminals (and I guess also if you want something DOS or http headers like). | |
// Needed for raw mode terminals (and I guess also if you want something DOS or HTTP headers like). |
if !t.IsTerminal() { | ||
t.Out = os.Stderr // no need to add \r for non raw mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Out = os.Stderr // no need to add \r for non raw mode. | |
t.Out = os.Stderr // no need to add \r for non-raw mode. |
type Terminal struct { | ||
fd int | ||
oldState *term.State | ||
term *term.Terminal | ||
Out io.Writer | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type Terminal struct { | |
fd int | |
oldState *term.State | |
term *term.Terminal | |
Out io.Writer | |
} | |
type Terminal struct { | |
*term.Terminal | |
fd int | |
oldState *term.State | |
Out io.Writer | |
} |
Maybe this, would avoid to define Readline and SetPrompt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to control the exact exposed surface vs having users know both packages/types
but maybe... tbd
|
||
func (t *Terminal) ReadLine() (string, error) { | ||
return t.term.ReadLine() | ||
} | ||
|
||
func (t *Terminal) SetPrompt(s string) { | ||
t.term.SetPrompt(s) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (t *Terminal) ReadLine() (string, error) { | |
return t.term.ReadLine() | |
} | |
func (t *Terminal) SetPrompt(s string) { | |
t.term.SetPrompt(s) | |
} |
See #1 (comment)
/* | ||
if isTerm { | ||
cli.UntilInterrupted() | ||
} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it's gone now
@@ -8,6 +8,8 @@ require ( | |||
golang.org/x/term v0.23.0 | |||
) | |||
|
|||
// replace fortio.org/cli => ../cli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing fortio/cli#38