Archived
1
0

Merge branch 'master' of git.recondor.com:recondor/gastenboek

This commit is contained in:
Jip J. Dekker 2013-10-22 15:21:10 +02:00
commit 74807223bb
3 changed files with 79 additions and 10 deletions

View File

@ -41,7 +41,7 @@ func generateMenu() string {
var width, height int = terminalSize()
if menu == "" && width != menuwidth {
menuwidth = width
if width-3 < asciiLen {
if width >= asciiLen+4 {
var content []string = strings.Split(ascii, "\n")
var options []string = strings.Split(tekst, "\n")

View File

@ -101,6 +101,10 @@ func makeEntry() bool {
} else if len(name) > maxName {
name = name[:maxName-1]
}
name = strings.TrimSpace(name)
if name == "" {
name = "Anonymous"
}
fmt.Printf("\n\nSchrijf hieronder uw bericht aan het nieuwe bestuur van Thalia.\nU kunt alle tekens binnen de unicode gebruiken, u kunt maximaal %d bytes gebruiken.\nU Schrijft per regel, dus nadat een regel getypt is, is deze definitief.\nSluit uw bericht af met een regel \"Aldus ons bericht.\", u kunt het bericht daarna nog persoonlijk ondertekenen.\n", maxContent)
var width, _ int = terminalSize()

View File

@ -1,23 +1,88 @@
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
func listFiles(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
fmt.Println(info.Name() + " - " + path)
const (
timeLayout = "3:04pm (MST)"
)
var (
entries []string
)
func listFilenames() {
for i, val := range entries {
val = strings.Trim(val, ".txt")
val = strings.Trim(val, "\n")
parts := strings.Split(val, " ")
unix, _ := strconv.ParseInt(parts[0], 10, 64)
t := time.Unix(unix, 0)
fmt.Printf("%d) %v - %v \n", i+1, t.Format(timeLayout), parts[1])
}
}
func getFilenames(path string, info os.FileInfo, err error) error {
if !info.IsDir() && info.Name() == path && filepath.Ext(path) == ".txt" {
entries = append(entries, path)
}
return nil
}
func viewEntry() {
clear()
filepath.Walk(".", filepath.WalkFunc(listFiles))
func showFile(i int) {
f, openErr := os.Open(entries[i])
if openErr != nil {
fmt.Printf("\n\tCouldn't open file: %v", openErr)
return
}
defer f.Close()
reader := bufio.NewReader(f)
user := bufio.NewReader(os.Stdin)
fmt.Print("\nSelecteer hier welk bericht u graag zou willen lezen: ")
var i int
fmt.Scan(&i)
clear()
fmt.Print("Druk op enter om volgende regels te zien en uiteindelijk terug te keren naar het keuzemenu.\n")
var width, height int = terminalSize()
fmt.Print(strings.Repeat("-", width-1) + "\n")
var lines int
var done bool = false
for !done {
line, err := reader.ReadString('\n')
done = err != nil
fmt.Print(line)
if lines >= height {
user.ReadString('\n')
}
lines++
}
fmt.Print(strings.Repeat("-", width-1) + "\n")
user.ReadString('\n')
}
func viewEntry() {
entries = make([]string, 0)
err := filepath.Walk(".", filepath.WalkFunc(getFilenames))
if err != nil {
return
}
for {
clear()
listFilenames()
fmt.Printf("\nKies hier welk bericht u graag zou willen lezen, toets 0 om terug te keren naar het menu: ")
var i int
fmt.Scan(&i)
if i > 0 && i <= len(entries) {
showFile(i - 1)
} else {
return
}
}
}