Skip to content

Commit

Permalink
Rename middleware to readWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
mgazza committed Oct 27, 2024
1 parent d950d7a commit 3aa5f6e
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ type Terminal struct {
ctrlPressed bool
altPressed bool
}
newLineMode bool // new line mode or line feed mode
bracketedPasteMode bool
state *parseState
blinking bool
printData []byte
printer Printer
cmd *exec.Cmd
middleware Middleware
newLineMode bool // new line mode or line feed mode
bracketedPasteMode bool
state *parseState
blinking bool
printData []byte
printer Printer
cmd *exec.Cmd
readWriterConfigurator ReadWriterConfigurator
}

// Printer is used for spooling print data when its received.
Expand Down Expand Up @@ -269,8 +269,8 @@ func (t *Terminal) open() error {
}

t.in, t.out = in, out
if t.middleware != nil {
t.out, t.in = t.middleware.SetupMiddleware(out, in)
if t.readWriterConfigurator != nil {
t.out, t.in = t.readWriterConfigurator.SetupReadWriter(out, in)
}

t.pty = pty
Expand Down Expand Up @@ -359,8 +359,8 @@ func (t *Terminal) RunWithConnection(in io.WriteCloser, out io.Reader) error {
time.Sleep(time.Millisecond * 50)
}
t.in, t.out = in, out
if t.middleware != nil {
t.out, t.in = t.middleware.SetupMiddleware(out, in)
if t.readWriterConfigurator != nil {
t.out, t.in = t.readWriterConfigurator.SetupReadWriter(out, in)
}

t.run()
Expand Down Expand Up @@ -505,19 +505,19 @@ func (t *Terminal) DragEnd() {
t.selecting = false
}

// SetMiddleware sets the middleware function that will be used when creating a new terminal.
// The middleware function is responsible for setting up the I/O readers and writers.
func (t *Terminal) SetMiddleware(mw Middleware) {
t.middleware = mw
// SetReadWriter sets the readWriterConfigurator function that will be used when creating a new terminal.
// The readWriterConfigurator function is responsible for setting up the I/O readers and writers.
func (t *Terminal) SetReadWriter(mw ReadWriterConfigurator) {
t.readWriterConfigurator = mw
}

// Middleware is an interface that defines the methods required to set up
// ReadWriterConfigurator is an interface that defines the methods required to set up
// the input (reader) and output (writer) streams for the terminal.
// Implementations of this interface can modify or wrap the reader and writer.
type Middleware interface {
// SetupMiddleware configures the input and output streams for the terminal.
type ReadWriterConfigurator interface {
// SetupReadWriter configures the input and output streams for the terminal.
// It takes an input reader (r) and an output writer (w) as arguments.
// The function returns a possibly modified reader and writer that
// the terminal will use for I/O operations.
SetupMiddleware(r io.Reader, w io.WriteCloser) (io.Reader, io.WriteCloser)
SetupReadWriter(r io.Reader, w io.WriteCloser) (io.Reader, io.WriteCloser)
}

0 comments on commit 3aa5f6e

Please sign in to comment.