espelhamento de
https://github.com/quitesimpleorg/hs9001.git
sincronizado 2024-11-28 22:12:36 +01:00
Albert S
bb2450b8ec
Starting search with the first character leads to a noticable delay. This hack ensures a more pleasant experience.
72 linhas
1.5 KiB
Go
72 linhas
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"io"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
type history struct {
|
|
conn *sql.DB
|
|
}
|
|
|
|
func (h *history) GetHistoryByPrefix(prefix string) (ph []string) {
|
|
/* Hack for performance reasons */
|
|
if len(prefix) < 2 {
|
|
return
|
|
}
|
|
opts := searchopts{}
|
|
opts.order = "DESC"
|
|
cmdqry := prefix + "%"
|
|
opts.command = &cmdqry
|
|
results := search(h.conn, opts)
|
|
for e := results.Front(); e != nil; e = e.Next() {
|
|
entry, ok := e.Value.(*HistoryEntry)
|
|
if !ok {
|
|
log.Panic("Failed to retrieve entries")
|
|
}
|
|
ph = append(ph, entry.cmd)
|
|
}
|
|
return
|
|
}
|
|
func (h *history) GetHistoryByPattern(pattern string) (ph []string, pos []int) {
|
|
/* Hack for performance reasons */
|
|
if len(pattern) < 2 {
|
|
return
|
|
}
|
|
opts := searchopts{}
|
|
opts.order = "DESC"
|
|
cmdqry := "%" + pattern + "%"
|
|
opts.command = &cmdqry
|
|
results := search(h.conn, opts)
|
|
for e := results.Front(); e != nil; e = e.Next() {
|
|
entry, ok := e.Value.(*HistoryEntry)
|
|
if !ok {
|
|
log.Panic("Failed to retrieve entries")
|
|
}
|
|
ph = append(ph, entry.cmd)
|
|
pos = append(pos, strings.Index(strings.ToLower(entry.cmd), strings.ToLower(pattern)))
|
|
}
|
|
return
|
|
}
|
|
|
|
func (h *history) ReadHistory(r io.Reader) (num int, err error) {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) WriteHistory(w io.Writer) (num int, err error) {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) AppendHistory(item string) {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) ClearHistory() {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) RLock() {
|
|
//noop
|
|
}
|
|
func (h *history) RUnlock() {
|
|
//noop
|
|
}
|