mirror of https://github.com/nealey/spongy
Keep keyboard focus in input
This commit is contained in:
parent
2a0c9231d7
commit
03dd0a9b81
|
@ -14,7 +14,7 @@
|
|||
<input type="hidden" name="auth" value="" id="authtok">
|
||||
<input type="hidden" name="type" value="command">
|
||||
<input type="hidden" name="target" id="target">
|
||||
<input name="text" autofocus>
|
||||
<input name="text" id="text" autofocus>
|
||||
<input type="Submit" value="Send">
|
||||
</form>
|
||||
<div id="kiboze"></div>
|
||||
|
|
|
@ -29,10 +29,20 @@ func ReadString(fn string) string {
|
|||
return strings.TrimSpace(string(octets))
|
||||
}
|
||||
|
||||
func tail(w http.ResponseWriter, pos int64) {
|
||||
logfn := path.Join(ServerDir, "log")
|
||||
func tail(w http.ResponseWriter, filename string, pos int64) {
|
||||
var err error
|
||||
|
||||
f, err := os.Open(logfn)
|
||||
currentfn := path.Join(ServerDir, "current")
|
||||
if filename == "" {
|
||||
filename, err = os.Readlink(currentfn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
filepath := path.Join(ServerDir, filename)
|
||||
|
||||
f, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -43,7 +53,7 @@ func tail(w http.ResponseWriter, pos int64) {
|
|||
log.Fatal(err)
|
||||
}
|
||||
defer watcher.Close()
|
||||
watcher.Add(logfn)
|
||||
watcher.Add(filepath)
|
||||
|
||||
for {
|
||||
printid := false
|
||||
|
@ -52,22 +62,33 @@ func tail(w http.ResponseWriter, pos int64) {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if newpos < pos {
|
||||
// File has been truncated!
|
||||
pos = 0
|
||||
f.Seek(0, 0)
|
||||
|
||||
if newpos != pos {
|
||||
log.Fatal("Lost my position in the log, somehow (log truncated?)")
|
||||
}
|
||||
|
||||
|
||||
bf := bufio.NewScanner(f)
|
||||
for bf.Scan() {
|
||||
t := bf.Text()
|
||||
pos += int64(len(t)) + 1 // XXX: this breaks if we ever see \r\n
|
||||
|
||||
parts := strings.Split(t, " ")
|
||||
if (len(parts) >= 4) && (parts[3] == "NEXTLOG") {
|
||||
watcher.Remove(filepath)
|
||||
filename = parts[4]
|
||||
filepath = path.Join(ServerDir, filename)
|
||||
f.Close()
|
||||
f, err = os.Open(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
watcher.Add(filename)
|
||||
}
|
||||
fmt.Fprintf(w, "data: %s\n", t)
|
||||
printid = true
|
||||
}
|
||||
if printid {
|
||||
_, err = fmt.Fprintf(w, "id: %d\n\n", pos)
|
||||
_, err = fmt.Fprintf(w, "id: %s/%d\n\n", filename, pos)
|
||||
}
|
||||
if err != nil {
|
||||
break
|
||||
|
@ -127,8 +148,14 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
handleCommand(w, r.Form.Get("text"), r.FormValue("target"))
|
||||
default:
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
id, _ := strconv.ParseInt(os.Getenv("HTTP_LAST_EVENT_ID"), 0, 64)
|
||||
tail(w, id)
|
||||
parts := strings.Split(os.Getenv("HTTP_LAST_EVENT_ID"), "/")
|
||||
if len(parts) == 2 {
|
||||
filename := path.Base(parts[0])
|
||||
pos, _ := strconv.ParseInt(parts[1], 0, 64)
|
||||
tail(w, filename, pos)
|
||||
} else {
|
||||
tail(w, "", 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"logfile"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -24,6 +25,7 @@ type Message struct {
|
|||
var running bool = true
|
||||
var nick string
|
||||
var gecos string
|
||||
var maxlogsize uint
|
||||
var logq chan Message
|
||||
|
||||
func isChannel(s string) bool {
|
||||
|
@ -45,13 +47,11 @@ func (m Message) String() string {
|
|||
}
|
||||
|
||||
func logLoop() {
|
||||
logf, err := os.OpenFile("log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
logf := logfile.NewLogfile(int(maxlogsize))
|
||||
defer logf.Close()
|
||||
|
||||
for m := range logq {
|
||||
fmt.Fprintf(logf, "%d %s\n", time.Now().Unix(), m.String())
|
||||
logf.Log(m.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,6 +220,7 @@ func usage() {
|
|||
func main() {
|
||||
dotls := flag.Bool("notls", true, "Disable TLS security")
|
||||
outqdir := flag.String("outq", "outq", "Output queue directory")
|
||||
flag.UintVar(&maxlogsize, "logsize", 8000, "Log entries before rotating")
|
||||
flag.StringVar(&gecos, "gecos", "Bob The Merry Slug", "Gecos entry (full name)")
|
||||
|
||||
flag.Parse()
|
||||
|
|
11
wirc.js
11
wirc.js
|
@ -127,9 +127,15 @@ function addMessage(txt) {
|
|||
var args = parts.slice(5);
|
||||
var msg = txt.substr(lhs.length + 2)
|
||||
|
||||
var forumElement = getForumElement(forum);
|
||||
var forumElement;
|
||||
var p = document.createElement("p");
|
||||
|
||||
if (command == "NICK") {
|
||||
forumElement = getForumElement(".");
|
||||
} else {
|
||||
forumElement = getForumElement(forum);
|
||||
}
|
||||
|
||||
addMessagePart(p, "timestamp", ts.toLocaleTimeString());
|
||||
|
||||
switch (command) {
|
||||
|
@ -188,6 +194,9 @@ function init() {
|
|||
source.onmessage = newmsg;
|
||||
|
||||
document.getElementById("command").onsubmit = handleCommand;
|
||||
|
||||
var txte = document.getElementById("text");
|
||||
txte.addEventListener("blur", txte.focus);
|
||||
}
|
||||
|
||||
window.onload = init;
|
||||
|
|
Loading…
Reference in New Issue