mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-22 20:34:26 +00:00
For the brevity of the code, I changed the print format of arguments.
This commit is contained in:
parent
24549dca01
commit
0620cb5c2c
@ -93,17 +93,13 @@ func (wt *WebTTY) Run(ctx context.Context) error {
|
|||||||
errs <- func() error {
|
errs <- func() error {
|
||||||
buffer := make([]byte, wt.bufferSize)
|
buffer := make([]byte, wt.bufferSize)
|
||||||
var line string
|
var line string
|
||||||
arguments, err := json.Marshal(wt.arguments)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for {
|
for {
|
||||||
n, err := wt.masterConn.Read(buffer)
|
n, err := wt.masterConn.Read(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrMasterClosed
|
return ErrMasterClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
err = wt.handleMasterReadEvent(buffer[:n], &line, arguments)
|
err = wt.handleMasterReadEvent(buffer[:n], &line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -172,7 +168,7 @@ func (wt *WebTTY) masterWrite(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wt *WebTTY) handleMasterReadEvent(data []byte, line *string, argument []byte) error {
|
func (wt *WebTTY) handleMasterReadEvent(data []byte, line *string) error {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return errors.New("unexpected zero length read from master")
|
return errors.New("unexpected zero length read from master")
|
||||||
}
|
}
|
||||||
@ -198,7 +194,7 @@ func (wt *WebTTY) handleMasterReadEvent(data []byte, line *string, argument []by
|
|||||||
// 13(ASCII) means carriage return(CR)
|
// 13(ASCII) means carriage return(CR)
|
||||||
// it is the end of a line
|
// it is the end of a line
|
||||||
if decodedBuffer[n-1] == 13 {
|
if decodedBuffer[n-1] == 13 {
|
||||||
log.Printf("[write-log] %s %s\n", argument, *line)
|
log.Printf("[write-log] %v %s\n", wt.arguments, *line)
|
||||||
*line = ""
|
*line = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user