Documentation
¶
Overview ¶
Package command implements the Command design pattern. Typewriter acts as both the Invoker and Receiver in the Command pattern. It uses its own implementation of the CommandInvoker interface to execute each command sequentially, with the ability to undo every action. All commands interact with the Typewriter through its internal TypewriterController, which exposes the available actions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Command ¶
type Command interface {
Undo()
Execute()
}
Command defines the command interface for the actions.
type CommandInvoker ¶
type CommandInvoker interface {
Press(Command) CommandInvoker
UndoLast() CommandInvoker
}
CommandInvoker defines the invoking interface.
type PressBackspace ¶
type PressBackspace struct {
// contains filtered or unexported fields
}
PressBackspace implements backspace key press command.
func NewPressBackspace ¶
func NewPressBackspace(receiver *Typewriter) *PressBackspace
NewPressBackspace constructs the instance of the PressBackspace command.
func (*PressBackspace) Execute ¶
func (p *PressBackspace) Execute()
Execute implements the execution method of the command.
func (*PressBackspace) Undo ¶
func (p *PressBackspace) Undo()
Undo implements the undoing method of the command.
type PressCharacter ¶
type PressCharacter struct {
// contains filtered or unexported fields
}
PressCharacter implements a single character key press command.
func NewPressCharacter ¶
func NewPressCharacter(receiver *Typewriter) *PressCharacter
NewPressCharacter constructs the instance of the PressCharacter command.
func (*PressCharacter) Execute ¶
func (p *PressCharacter) Execute()
Execute implements the execution method of the command.
func (*PressCharacter) Key ¶
func (p *PressCharacter) Key(char rune) *PressCharacter
Key implements the single character value setter for the command.
func (*PressCharacter) Undo ¶
func (p *PressCharacter) Undo()
Undo implements the undoing method of the command.
type PressEnter ¶
type PressEnter struct {
// contains filtered or unexported fields
}
PressEnter implements the Enter key press command.
func NewPressEnter ¶
func NewPressEnter(receiver *Typewriter) *PressEnter
NewPressEnter constructs the instance of the PressEnter command.
func (*PressEnter) Execute ¶
func (p *PressEnter) Execute()
Execute implements the execution method of the command.
func (*PressEnter) Undo ¶
func (p *PressEnter) Undo()
Undo implements the undoing method of the command.
type PressSpace ¶
type PressSpace struct {
// contains filtered or unexported fields
}
PressSpace implements the spacebar press command.
func NewPressSpace ¶
func NewPressSpace(receiver *Typewriter) *PressSpace
NewPressSpace constructs the instance of the PressSpace command.
func (*PressSpace) Execute ¶
func (p *PressSpace) Execute()
Execute implements the execution method of the command.
func (*PressSpace) Undo ¶
func (p *PressSpace) Undo()
Undo implements the undoing method of the command.
type PressTab ¶
type PressTab struct {
// contains filtered or unexported fields
}
PressTab implements the Tab key press command.
func NewPressTab ¶
func NewPressTab(receiver *Typewriter, tabSize byte) *PressTab
NewPressTab constructs the instance of the PressTab command.
type Printer ¶
type Printer interface {
Print()
}
Printer defines the printing interface of the receiver.
type Typewriter ¶
type Typewriter struct {
Draft string
Controller *TypewriterController
// contains filtered or unexported fields
}
Typewriter represents the command receiver with invoker methods.
func (*Typewriter) Press ¶
func (t *Typewriter) Press(cmd Command) CommandInvoker
Press implements the execution invoker method with adding to command history.
func (*Typewriter) UndoLast ¶
func (t *Typewriter) UndoLast() CommandInvoker
UndoLast implements the command invoker undo action from command history.
type TypewriterController ¶
type TypewriterController struct {
// contains filtered or unexported fields
}
TypewriterController implements all possible actions of the Typewriter receiver.
func NewTypewriterController ¶
func NewTypewriterController(tw *Typewriter) *TypewriterController
NewTypewriterController constructs a new TypewriterController instance.
func (*TypewriterController) PressBackspace ¶
func (tc *TypewriterController) PressBackspace() rune
PressBackspace implements the behaviour logic for the backspace key press.
func (*TypewriterController) PressCharacter ¶
func (tc *TypewriterController) PressCharacter(char rune)
PressCharacter implements the behaviour logic for the simple character key press.
func (*TypewriterController) PressEnter ¶
func (tc *TypewriterController) PressEnter()
PressEnter implements the behaviour logic for the Enter key press.
func (*TypewriterController) PressSpace ¶
func (tc *TypewriterController) PressSpace()
PressSpace implements the behaviour logic for the spacebar key press.
func (*TypewriterController) PressTab ¶
func (tc *TypewriterController) PressTab(tabSize byte)
PressTab implements the behaviour logic for the tab key press.