diff --git a/common/bootcommand/boot_command_ast.go b/common/bootcommand/boot_command_ast.go index 669f7f50d..98a4afc81 100644 --- a/common/bootcommand/boot_command_ast.go +++ b/common/bootcommand/boot_command_ast.go @@ -42,7 +42,8 @@ type expression interface { type expressionSequence []expression -// Do executes every expression in the sequence and then finalizes the driver. +// Do executes every expression in the sequence and then flushes remaining +// scancodes. func (s expressionSequence) Do(ctx context.Context, b BCDriver) error { // validate should never fail here, since it should be called before // expressionSequence.Do. Only reason we don't panic is so we can clean up. @@ -58,10 +59,10 @@ func (s expressionSequence) Do(ctx context.Context, b BCDriver) error { return err } } - return b.Finalize() + return b.Flush() } -// Do executes every expression in the sequence and then finalizes the driver. +// Validate tells us if every expression in the sequence is valid. func (s expressionSequence) Validate() (errs []error) { for _, exp := range s { if err := exp.Validate(); err != nil { @@ -91,7 +92,8 @@ type waitExpression struct { // Do waits the amount of time described by the expression. It is cancellable // through the context. -func (w *waitExpression) Do(ctx context.Context, _ BCDriver) error { +func (w *waitExpression) Do(ctx context.Context, driver BCDriver) error { + driver.Flush() log.Printf("[INFO] Waiting %s", w.d) select { case <-time.After(w.d): diff --git a/common/bootcommand/driver.go b/common/bootcommand/driver.go index ddbae0bc5..04b0eecd6 100644 --- a/common/bootcommand/driver.go +++ b/common/bootcommand/driver.go @@ -6,6 +6,6 @@ const shiftedChars = "~!@#$%^&*()_+{}|:\"<>?" type BCDriver interface { SendKey(key rune, action KeyAction) error SendSpecial(special string, action KeyAction) error - // Finalize will be called after every expression has been processed. - Finalize() error + // Flush will be called when we want to send scancodes to the VM. + Flush() error } diff --git a/common/bootcommand/pc_xt_driver.go b/common/bootcommand/pc_xt_driver.go index de148e42e..8b6a75d92 100644 --- a/common/bootcommand/pc_xt_driver.go +++ b/common/bootcommand/pc_xt_driver.go @@ -111,8 +111,8 @@ func NewPCXTDriver(send SendCodeFunc, chunkSize int) *pcXTDriver { } } -// Finalize flushes all scanecodes. -func (d *pcXTDriver) Finalize() error { +// Flush send all scanecodes. +func (d *pcXTDriver) Flush() error { defer func() { d.buffer = nil }() @@ -162,6 +162,7 @@ func (d *pcXTDriver) SendSpecial(special string, action KeyAction) error { if !ok { return fmt.Errorf("special %s not found.", special) } + log.Printf("Special code '%s' '<%s>' found, replacing with: %v", action.String(), special, keyCode) switch action { case KeyOn: @@ -174,7 +175,7 @@ func (d *pcXTDriver) SendSpecial(special string, action KeyAction) error { return nil } -// send stores the codes in an internal buffer. Use finalize to flush them. +// send stores the codes in an internal buffer. Use Flush to send them. func (d *pcXTDriver) send(codes []string) { d.buffer = append(d.buffer, codes) } diff --git a/common/bootcommand/pc_xt_driver_test.go b/common/bootcommand/pc_xt_driver_test.go index ca4f5eb3d..b3a3c94ea 100644 --- a/common/bootcommand/pc_xt_driver_test.go +++ b/common/bootcommand/pc_xt_driver_test.go @@ -86,3 +86,22 @@ func Test_pcxtSpecialLookup(t *testing.T) { assert.NoError(t, err) assert.Equal(t, expected, codes) } + +func Test_flushes(t *testing.T) { + in := "abc123098" + expected := [][]string{ + {"1e", "9e", "30", "b0", "2e", "ae", "02", "82", "03", "83", "04", "84"}, + {"0b", "8b", "0a", "8a", "09", "89"}, + } + var actual [][]string + sendCodes := func(c []string) error { + actual = append(actual, c) + return nil + } + d := NewPCXTDriver(sendCodes, -1) + seq, err := GenerateExpressionSequence(in) + assert.NoError(t, err) + err = seq.Do(context.Background(), d) + assert.NoError(t, err) + assert.Equal(t, expected, actual) +} diff --git a/common/bootcommand/vnc_driver.go b/common/bootcommand/vnc_driver.go index 86d6497c1..dfe75b9b2 100644 --- a/common/bootcommand/vnc_driver.go +++ b/common/bootcommand/vnc_driver.go @@ -92,8 +92,8 @@ func (d *vncDriver) keyEvent(k uint32, down bool) error { return nil } -// Finalize does nothing here -func (d *vncDriver) Finalize() error { +// Flush does nothing here +func (d *vncDriver) Flush() error { return nil }