better organize the package and make main a test
This commit is contained in:
parent
5b835d0a61
commit
1f871b5339
20
requivalence/equivalence.go
Normal file
20
requivalence/equivalence.go
Normal file
@ -0,0 +1,20 @@
|
||||
package requivalence
|
||||
|
||||
type equivalenceTable map[rune]rune
|
||||
|
||||
type EquivalenceTable struct {
|
||||
et equivalenceTable
|
||||
}
|
||||
|
||||
func (table EquivalenceTable) Normalize(r rune) rune {
|
||||
if normal, ok := table.et[r]; ok {
|
||||
return normal
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
var Equivalence = EquivalenceTable{
|
||||
et: equivalenceTable{
|
||||
'a': 'a',
|
||||
},
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package vt220
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -67,6 +67,7 @@ func (r *GraphicRange) load(gOverlay *CharacterSet) {
|
||||
r.set[*graph] = &r.table[i][j]
|
||||
}
|
||||
}
|
||||
// fmt.Printf("%+v", r.set)
|
||||
}
|
||||
|
||||
func (rg *GraphicRange) lockShift(register GraphicRegister, w io.Writer) error {
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package vt220
|
||||
|
||||
import (
|
||||
"io"
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package vt220
|
||||
|
||||
type equivalenceTable map[rune]rune
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package vt220
|
||||
|
||||
type Grapheme *rune
|
||||
|
@ -1,14 +1,12 @@
|
||||
package main
|
||||
package vt220
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
var (
|
||||
VT220Type = TermType{"vt220"}
|
||||
requiv "git.sdf.org/CRThaze/vtTools/requivalence"
|
||||
)
|
||||
|
||||
type graphicRegister struct {
|
||||
@ -32,7 +30,7 @@ type VT220 struct {
|
||||
fontBuffer **CharacterSet
|
||||
}
|
||||
|
||||
func newVT220(w io.Writer) *VT220 {
|
||||
func NewVT220(w io.Writer) *VT220 {
|
||||
return &VT220{
|
||||
writer: w,
|
||||
c0: ControlRange{
|
||||
@ -141,7 +139,7 @@ func (vt *VT220) LockShift(registerIndex int, right bool) error {
|
||||
if right {
|
||||
rg = vt.gr
|
||||
}
|
||||
return rg.lockShift(vt.graphicRegistry[registerIndex], vt)
|
||||
return rg.lockShift(vt.graphicRegistry[registerIndex], vt.writer)
|
||||
}
|
||||
|
||||
func (vt *VT220) SingleShiftRune(registerIndex int, r rune) ([]byte, error) {
|
||||
@ -239,7 +237,7 @@ func (vt *VT220) TransDynamic(r rune) []byte {
|
||||
}
|
||||
}
|
||||
for i, set := range vt.graphicRepetoire {
|
||||
if !set.lookup.Has(r) {
|
||||
if set == nil || !set.lookup.Has(r) {
|
||||
continue
|
||||
}
|
||||
// TODO: Don't leave this in the register.
|
||||
@ -258,7 +256,7 @@ func (vt *VT220) TransDynamic(r rune) []byte {
|
||||
// SafeTrans uses an equivalency table for the given rune to determine a similiar rune that is
|
||||
// present in the GraphicRepetoir. It then calls TransDynamic with that rune.
|
||||
func (vt *VT220) SafeTransDynamic(r rune) []byte {
|
||||
return vt.TransDynamic(Equivalence.Normalize(r))
|
||||
return vt.TransDynamic(requiv.Equivalence.Normalize(r))
|
||||
}
|
||||
|
||||
func (vt VT220) write(buf *bytes.Buffer) (n int, err error) {
|
@ -1,11 +1,12 @@
|
||||
package main
|
||||
package vt220
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var term = NewVTTerm(VT220Type, os.Stdout)
|
||||
var term = NewVT220(os.Stdout)
|
||||
|
||||
var testMSCASCIIGraphic = [16][6]rune{
|
||||
{' ', '0', '@', 'P', '`', 'p'},
|
||||
@ -90,10 +91,10 @@ func printTest(sl, sr [16][6]rune) {
|
||||
term.Print("\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
func TestOutput(t *testing.T) {
|
||||
term.Init()
|
||||
printTest(testMSCASCIIGraphic, testMSCSupplementalGraphic)
|
||||
// term.(*VT220).LockShift(2, true)
|
||||
term.LockShift(2, true)
|
||||
printTest(testMSCASCIIGraphic, testSpecialGraphics)
|
||||
// term.(*VT220).LockShift(1, true)
|
||||
term.LockShift(1, true)
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package main
|
||||
package vttools
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"git.sdf.org/CRThaze/vtTools/vt220"
|
||||
)
|
||||
|
||||
type TermType struct {
|
||||
@ -16,6 +18,10 @@ func (id TermType) String() string {
|
||||
return id.ID()
|
||||
}
|
||||
|
||||
var (
|
||||
VT220Type = TermType{"vt220"}
|
||||
)
|
||||
|
||||
type VTTerm interface {
|
||||
io.Writer
|
||||
Init()
|
||||
@ -29,7 +35,7 @@ func NewVTTerm(ttype TermType, w io.Writer) VTTerm {
|
||||
var term VTTerm
|
||||
switch ttype {
|
||||
case VT220Type:
|
||||
term = newVT220(w)
|
||||
term = vt220.NewVT220(w)
|
||||
}
|
||||
return term
|
||||
}
|
Loading…
Reference in New Issue
Block a user