Comments (18)
I've finished the color-aware tabwriter modification, so I will submit a PR later which will replace the dependency text/tabwriter
with github.com/NonerKao/color-aware-tabwriter
.
from ultralist.
I noticed that without color.Italic
https://github.com/gammons/todolist/blob/master/todolist/formatter.go#L49 it works fine.
Also it works with color.Italic
but with different format string " %s \t%s\t%s\t%s\t\n"
(additional space after first %s
) https://github.com/gammons/todolist/blob/master/todolist/formatter.go#L51
from ultralist.
@vokiel oh nice. Do you want to submit a PR for that?
from ultralist.
It depends on the desired output. For me bold is enough, others may want both (bold + italic).
In the second, extra space could be fine. Or maybe it would be better to do more digging into formatter and/or http://github.com/fatih/color (what exactly Italic adds to the output). I would also check if concatenating strings work better in this case.
from ultralist.
Hey @vokiel, did you manage to reproduce the error consistently?
from ultralist.
Hi @mikezter, I've did a simple check on sample based on the todolist:
package main
import (
"fmt"
"text/tabwriter"
"github.com/fatih/color"
"strconv"
"os"
)
type Formatter struct {
Writer *tabwriter.Writer
}
func main() {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
f := &Formatter{Writer: w}
yellow := color.New(color.FgYellow)
yellow.Add(color.Italic)
yellow.Add(color.Bold)
fmt.Fprintf(f.Writer, " %s\t%s\t%s\n", yellow.SprintFunc()(strconv.Itoa(43)), "[ ]","Just a simple text")
f.Writer.Flush()
}
Results:
root@f0a9f6131ae8:/usr/src/myapp# go run app.go
43[ ] Just a simple text
With yellow.Add(color.Italic)
commented-out
root@f0a9f6131ae8:/usr/src/myapp# go run app.go
43 [ ] Just a simple text
from ultralist.
it looks like yellow.Add(...)
swallows the tab character. What are the control characters inserted by yellow.Add(color.Italic)
?
from ultralist.
I think the relevant code of package color is here https://github.com/fatih/color/blob/master/color.go#L365 and here https://github.com/fatih/color/blob/master/color.go#L346
constants are defined here: https://github.com/fatih/color/blob/master/color.go#L45
I am not too familiar with ANSI escapes (or ist SGR?) so i'm interested to learn about the problem here.
from ultralist.
I modified the test program from @vokiel and instead of
fmt.Fprintf(f.Writer, " %s\t%s\t%s\n", yellow.SprintFunc()(strconv.Itoa(43)), "[ ]","Just a simple text")
I printed the string directly to the console with
var t = fmt.Sprintf(" %s\t%s\t%s\n", yellow.SprintFunc()(strconv.Itoa(43)), "[ ]","Just a simple text")
fmt.Print(t)
The result is
43 [ ] Just a simple text
(this looks alright)
It looks like tabwriter
is the culprit
from ultralist.
Update:
I was able to isolate the issue and it repro it with the least amount of data:
Save the following json as .todos.json
and run todolist l
and you will see it.
[{
"id": 10,
"subject": "Task 1",
"projects": [],
"contexts": [],
"due": "",
"completed": false,
"completedDate": "",
"archived": false,
"isPriority": true
}]
The issue is that the id
is double digit. With single digits this issue doesn't happen at all.
The test data in the repo doesn't have this combination of double digit and isPriority
from ultralist.
Any updates? I found this, which states that color
and tabwriter
are not compatible to each other.
from ultralist.
@NonerKao that was also my observation. The tabwriter is confused by the additional control characters. I was looking into changing the tabwriter to add support for those control sequences. I'm currently traveling and don't have support to my machine, but when I'm back in 8 days I'd like to setup a PR with my changes.
from ultralist.
@ingorichter That's great! Looking forward to the fix :)
Just FYI, the text/tabwriter
is official and The text/tabwriter package is frozen and is not accepting new features. (text/tabwriter/tabwriter.go:11)
So maybe fixing fatih/color
would be another choice? Maybe something like this patch at fatih/color would be helpful.
from ultralist.
Any news?
from ultralist.
I ran some tests using @prataprc 's patch to color
but it seems to still have not fixed the issue.
from ultralist.
Because the root cause lies in tabwriter
and its algorithm.
I will deal with this recently.
from ultralist.
Okay, now I'm way behind of the things I wanted to do after my long trip. Thanks for putting up the fix. I'll check it out in the afternoon. 👍
from ultralist.
@ingorichter Thanks for the survey! What you pointed out was pretty helpful for me to submit this patch.
from ultralist.
Related Issues (20)
- Requiring libc6 2.32. Ubuntu 20.04 LTS only has libc6 2.31 HOT 5
- Change output of gc command HOT 1
- Same todo id keeps saying deleted..
- [Feature Request] Support for more granular recurrence
- Colorscheme unreadable when using light theme
- [Feature request] Add autocomplete to bash and zsh HOT 1
- Adding more options to due:
- Status of 500 Internal Server Error from server
- Reccurrence seems not worked HOT 1
- ultralist e 23 recur:none not working
- Enhancement: Listing task should display the nature of task like Recurrence/Until etc HOT 1
- ultralist l --status=false displays the status column HOT 1
- [bug]: 'thisweek' doesn't work in the date parser HOT 3
- Recurrence not working properly when synchronized with ultraist pro
- How can I contribute? HOT 2
- [Feature Request] Quickly add a context HOT 3
- Please bump golang.org/x/sys dependency to support build on riscv64-freebsd
- Bug: ultralist e
- Feature request: Confirmation on complete or delete HOT 1
- `go get` deprecated & `go install` doesn't work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ultralist.