Make sure ooniprobe show <id> is WAI (#61)
1. the description of the command and the helper function are clear hints that the command is intended to show a single JSON measurement at a time (also the use case seems clear) [*] 2. the function used to read lines was failing for all my measurements that take input. Since that was not the optimal pattern anyway, use a better pattern to fix it. 3. some changes are automatically applied by my editor (VSCode with the Go plugin) and I am fine with them. 4. while reading code, I also applied my preferred pattern wrt whitespaces, i.e.: no whitespace inside functions, if a function feels too long in this way, just break it. Closes #57 [*] Even if we want to show many measurements at a time, which does not seem needed, given the UI patterns, this functionality won't be P0. What is P0 is to bless a new beta and give to @sarathms binaries for all archs that support a basic `show`.
This commit is contained in:
parent
f3865d2ec0
commit
7cde93fca4
4 changed files with 17 additions and 49 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
|
|
@ -30,6 +29,8 @@ var ansiEscapes = regexp.MustCompile(`[\x1B\x9B][[\]()#;?]*` +
|
|||
`(?:(?:(?:[a-zA-Z\d]*(?:;[a-zA-Z\\d]*)*)?\x07)` +
|
||||
`|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PRZcf-ntqry=><~]))`)
|
||||
|
||||
// EscapeAwareRuneCountInString counts the number of runes in a
|
||||
// string taking into account escape sequences.
|
||||
func EscapeAwareRuneCountInString(s string) int {
|
||||
n := utf8.RuneCountInString(s)
|
||||
for _, sm := range ansiEscapes.FindAllString(s, -1) {
|
||||
|
|
@ -38,6 +39,7 @@ func EscapeAwareRuneCountInString(s string) int {
|
|||
return n
|
||||
}
|
||||
|
||||
// RightPadd adds right padding in from of a string
|
||||
func RightPad(str string, length int) string {
|
||||
c := length - EscapeAwareRuneCountInString(str)
|
||||
if c < 0 {
|
||||
|
|
@ -113,17 +115,3 @@ func WrapString(s string, lim uint) string {
|
|||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// ReadLine will read a single line from a bufio.Reader
|
||||
func ReadLine(r *bufio.Reader) (string, error) {
|
||||
var (
|
||||
isPrefix bool
|
||||
err error
|
||||
line, ln []byte
|
||||
)
|
||||
for isPrefix && err == nil {
|
||||
line, isPrefix, err = r.ReadLine()
|
||||
ln = append(ln, line...)
|
||||
}
|
||||
return string(ln), err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue