mirror of
https://github.com/JetSetIlly/Gopher2600.git
synced 2025-04-02 11:02:17 -04:00
- result sub-package renamed to execution - renamed Instruction type therein to Instruction o disassembly - reworked structure of pacakge - better grep. scope of grep can now be specified - display sub-package added - disassemblies now store instance of display.DisasmInstruction instead of a formatted string o debugger - ammende GREP to support new disassembly features
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package debugger
|
|
|
|
// this file holds the functions/structures to be used when outputting to the
|
|
// terminal. The TermPrint functions of the Terminal interface should not be
|
|
// used directly.
|
|
|
|
import (
|
|
"fmt"
|
|
"gopher2600/debugger/terminal"
|
|
"strings"
|
|
)
|
|
|
|
// all print operations from the debugger should be made with the this print()
|
|
// function. output will be normalised and sent to the attached terminal as
|
|
// required.
|
|
func (dbg *Debugger) print(sty terminal.Style, s string, a ...interface{}) {
|
|
// resolve string placeholders, remove all trailing newlines, and return if
|
|
// the resulting string is empty
|
|
s = fmt.Sprintf(s, a...)
|
|
s = strings.TrimRight(s, "\n")
|
|
if len(s) == 0 {
|
|
return
|
|
}
|
|
|
|
dbg.term.TermPrint(sty, s)
|
|
|
|
// output to script file
|
|
if sty.IncludeInScriptOutput() {
|
|
dbg.scriptScribe.WriteOutput(s)
|
|
}
|
|
}
|
|
|
|
// styleWriter implements the io.Writer interface. it is useful for when an
|
|
// io.Writer is required and you want to direct the output to the terminal.
|
|
// allows the application of a single style.
|
|
type styleWriter struct {
|
|
dbg *Debugger
|
|
style terminal.Style
|
|
}
|
|
|
|
func (dbg *Debugger) printStyle(sty terminal.Style) *styleWriter {
|
|
return &styleWriter{
|
|
dbg: dbg,
|
|
style: sty,
|
|
}
|
|
}
|
|
|
|
func (wrt styleWriter) Write(p []byte) (n int, err error) {
|
|
wrt.dbg.print(wrt.style, string(p))
|
|
return len(p), nil
|
|
}
|