1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Pass PrefixWriter with driver name and version to DriverInit calls

This commit is contained in:
Achilleas Anagnostopoulos 2017-07-08 20:25:05 +01:00
parent 3485523cdc
commit 1b697fd125
3 changed files with 26 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package hal
import (
"bytes"
"gopheros/device"
"gopheros/device/tty"
"gopheros/device/video/console"
@ -13,7 +14,10 @@ type managedDevices struct {
activeTTY tty.Device
}
var devices managedDevices
var (
devices managedDevices
strBuf bytes.Buffer
)
// ActiveTTY returns the currently active TTY
func ActiveTTY() tty.Device {
@ -43,7 +47,10 @@ func DetectHardware() {
// each detected device. The function returns a list of device drivers that
// were successfully initialized.
func probe(hwProbeFns []device.ProbeFn) []device.Driver {
var drivers []device.Driver
var (
drivers []device.Driver
w = kfmt.PrefixWriter{Sink: kfmt.GetOutputSink()}
)
for _, probeFn := range hwProbeFns {
drv := probeFn()
@ -54,7 +61,7 @@ func probe(hwProbeFns []device.ProbeFn) []device.Driver {
strBuf.Reset()
major, minor, patch := drv.DriverVersion()
kfmt.Fprintf(&strBuf, "[hal] %s(%d.%d.%d): ", drv.DriverName(), major, minor, patch)
w.prefix = strBuf.Bytes()
w.Prefix = strBuf.Bytes()
if err := drv.DriverInit(&w); err != nil {
kfmt.Fprintf(&w, "init failed: %s\n", err.Message)

View File

@ -31,6 +31,14 @@ var (
outputSink io.Writer
)
// GetOutputSink returns the default target for calls to Printf.
func GetOutputSink() io.Writer {
if outputSink == nil {
return &earlyPrintBuffer
}
return outputSink
}
// SetOutputSink sets the default target for calls to Printf to w and copies
// any data accumulated in the earlyPrintBuffer to itt .
func SetOutputSink(w io.Writer) {

View File

@ -149,9 +149,17 @@ func TestPrintf(t *testing.T) {
},
}
if sink := GetOutputSink(); sink != &earlyPrintBuffer {
t.Fatal("expected GetOutputSink() to return the earlyPrintBuffer when no output sink has been set")
}
var buf bytes.Buffer
SetOutputSink(&buf)
if sink := GetOutputSink(); sink != &buf {
t.Fatal("expected GetOutputSink() to return the value passed to SetOutputSink")
}
for specIndex, spec := range specs {
buf.Reset()
spec.fn()