Add almost full option support

This commit is contained in:
Zachary Yedidia
2019-01-13 21:06:58 -05:00
parent 163ca36eeb
commit 7a20c2db76
16 changed files with 285 additions and 279 deletions

View File

@@ -1,34 +0,0 @@
package util
import (
"bufio"
"fmt"
"os"
"strconv"
"github.com/zyedidia/micro/cmd/micro/screen"
)
// TermMessage sends a message to the user in the terminal. This usually occurs before
// micro has been fully initialized -- ie if there is an error in the syntax highlighting
// regular expressions
// The function must be called when the Screen is not initialized
// This will write the message, and wait for the user
// to press and key to continue
func TermMessage(msg ...interface{}) {
screenb := screen.TempFini()
fmt.Println(msg...)
fmt.Print("\nPress enter to continue")
reader := bufio.NewReader(os.Stdin)
reader.ReadString('\n')
screen.TempStart(screenb)
}
// TermError sends an error to the user in the terminal. Like TermMessage except formatted
// as an error
func TermError(filename string, lineNum int, err string) {
TermMessage(filename + ", " + strconv.Itoa(lineNum) + ": " + err)
}

View File

@@ -6,6 +6,7 @@ import (
"os/user"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"unicode/utf8"
@@ -309,6 +310,19 @@ func GetCharPosInLine(b []byte, visualPos int, tabsize int) int {
return i
}
// ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off'
// as 'true' and 'false' respectively
func ParseBool(str string) (bool, error) {
if str == "on" {
return true, nil
}
if str == "off" {
return false, nil
}
return strconv.ParseBool(str)
}
// Clamp clamps a value between min and max
func Clamp(val, min, max int) int {
if val < min {
val = min