Added direction notes
This commit is contained in:
parent
7fd8d4fb6a
commit
b251e35be4
@ -1,6 +1,7 @@
|
|||||||
package kmb
|
package kmb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
query "github.com/tgckpg/golifehk/query"
|
query "github.com/tgckpg/golifehk/query"
|
||||||
@ -36,11 +37,21 @@ func ( this *QueryResult ) Message() ( string, error ) {
|
|||||||
sb.WriteString( "\n " )
|
sb.WriteString( "\n " )
|
||||||
for _, route := range *b.Routes {
|
for _, route := range *b.Routes {
|
||||||
utils.WriteMDv2Text( &sb, route.RouteId )
|
utils.WriteMDv2Text( &sb, route.RouteId )
|
||||||
|
if route.Direction == "O" {
|
||||||
|
sb.WriteString( "↑" )
|
||||||
|
} else if route.Direction == "I" {
|
||||||
|
sb.WriteString( "↓" )
|
||||||
|
}
|
||||||
|
if route.ServiceType != "1" {
|
||||||
|
utils.WriteMDv2Text( &sb, utils.ToPower( route.ServiceType ) )
|
||||||
|
}
|
||||||
sb.WriteString( " " )
|
sb.WriteString( " " )
|
||||||
}
|
}
|
||||||
sb.WriteString( "\n" )
|
sb.WriteString( "\n" )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Print( this.Query.Key )
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.String(), nil
|
return sb.String(), nil
|
||||||
|
@ -6,5 +6,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestQuerySchedule( t *testing.T ) {
|
func TestQuerySchedule( t *testing.T ) {
|
||||||
fmt.Print( Query( "zh", "大欖" ).Message() )
|
qo := Query( "zh-Hant", "68X" )
|
||||||
|
mesg, err := qo.Message()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf( "Unexpected Error: %s", err )
|
||||||
|
}
|
||||||
|
fmt.Println( mesg )
|
||||||
|
|
||||||
|
qo = Query( "zh-Hant", "K66 朗屏" )
|
||||||
|
mesg, err = qo.Message()
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf( "Expected Error: %s, got \"\" instead", mesg )
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,14 +58,21 @@ func Parse( line string, entries *[] ISearchable ) ( *QueryObject, error ) {
|
|||||||
return &QueryObject{ Key: Key, Results: &matches, SearchTerms: &terms }, nil
|
return &QueryObject{ Key: Key, Results: &matches, SearchTerms: &terms }, nil
|
||||||
} else if 0 < len( terms ) {
|
} else if 0 < len( terms ) {
|
||||||
for _, entry := range *entries {
|
for _, entry := range *entries {
|
||||||
|
anyFailed := false
|
||||||
for _, term := range terms {
|
for _, term := range terms {
|
||||||
if term.IsKey {
|
if term.IsKey {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ( Key == "" || Key == *entry.GetKey() ) && entry.Test( term.Value ) {
|
|
||||||
matches = append( matches, entry )
|
if !( ( Key == "" || Key == *entry.GetKey() ) && entry.Test( term.Value ) ) {
|
||||||
|
anyFailed = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !anyFailed {
|
||||||
|
matches = append( matches, entry )
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &QueryObject{ Key: Key, Results: &matches, SearchTerms: &terms }, nil
|
return &QueryObject{ Key: Key, Results: &matches, SearchTerms: &terms }, nil
|
||||||
}
|
}
|
||||||
|
@ -9,4 +9,8 @@ var WORKDIR string = TryGetEnv( "GOLIFEHK_WORKDIR", filepath.Join( os.TempDir(),
|
|||||||
|
|
||||||
var BOM string = bytes.NewBuffer([]byte{ 0xEF, 0xBB, 0xBF }).String()
|
var BOM string = bytes.NewBuffer([]byte{ 0xEF, 0xBB, 0xBF }).String()
|
||||||
|
|
||||||
const KEY_CHARS string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
|
var POWER_NUMBERS map[string] string = map[string] string {
|
||||||
|
"0": "⁰", "1": "¹", "2": "²", "3": "³",
|
||||||
|
"4": "⁴", "5": "⁵", "6": "⁶", "7": "⁷",
|
||||||
|
"8": "⁸", "9": "⁹",
|
||||||
|
}
|
||||||
|
@ -16,6 +16,13 @@ func WriteMDv2Text( sb *strings.Builder, t string ) {
|
|||||||
sb.WriteString( t )
|
sb.WriteString( t )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToPower( t string ) string {
|
||||||
|
for s, r := range POWER_NUMBERS {
|
||||||
|
t = strings.ReplaceAll( t, s, r )
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
func TryGetEnv[T any]( name string, fallback T ) T {
|
func TryGetEnv[T any]( name string, fallback T ) T {
|
||||||
v := os.Getenv( name )
|
v := os.Getenv( name )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user