Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
ad505816
Commit
ad505816
authored
Oct 19, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove ANSI codes when not connected to a TTY.
parent
1ed16cd0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
5 deletions
+23
-5
Main.py
Main.py
+14
-3
Utils.py
Utils.py
+5
-0
test/CommandTest.py
test/CommandTest.py
+4
-2
No files found.
Main.py
View file @
ad505816
...
@@ -16,6 +16,7 @@ from PrettyPrinter import *
...
@@ -16,6 +16,7 @@ from PrettyPrinter import *
from
PriorityCommand
import
PriorityCommand
from
PriorityCommand
import
PriorityCommand
import
TodoFile
import
TodoFile
import
TodoList
import
TodoList
from
Utils
import
escape_ansi
def
usage
():
def
usage
():
""" Prints the usage of the todo.txt CLI """
""" Prints the usage of the todo.txt CLI """
...
@@ -36,6 +37,17 @@ def arguments(p_start=2):
...
@@ -36,6 +37,17 @@ def arguments(p_start=2):
return
values
return
values
def
write
(
p_file
,
p_string
):
"""
Write p_string to file p_file, trailed by a newline character.
ANSI codes are removed when the file is not a TTY.
"""
if
not
p_file
.
isatty
():
p_string
=
escape_ansi
(
p_string
)
p_file
.
write
(
p_string
+
"
\
n
"
)
class
CLIApplication
(
object
):
class
CLIApplication
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
todolist
=
TodoList
.
TodoList
([])
self
.
todolist
=
TodoList
.
TodoList
([])
...
@@ -57,7 +69,6 @@ class CLIApplication(object):
...
@@ -57,7 +69,6 @@ class CLIApplication(object):
if
archive
.
is_dirty
():
if
archive
.
is_dirty
():
archive_file
.
write
(
str
(
archive
))
archive_file
.
write
(
str
(
archive
))
def
run
(
self
):
def
run
(
self
):
""" Main entry function. """
""" Main entry function. """
todofile
=
TodoFile
.
TodoFile
(
Config
.
FILENAME
)
todofile
=
TodoFile
.
TodoFile
(
Config
.
FILENAME
)
...
@@ -92,8 +103,8 @@ class CLIApplication(object):
...
@@ -92,8 +103,8 @@ class CLIApplication(object):
args
=
arguments
(
1
)
args
=
arguments
(
1
)
command
=
subcommand_map
[
subcommand
](
args
,
self
.
todolist
,
command
=
subcommand_map
[
subcommand
](
args
,
self
.
todolist
,
lambda
o
:
sys
.
stdout
.
write
(
o
+
"
\
n
"
),
lambda
o
:
write
(
sys
.
stdout
,
o
+
"
\
n
"
),
lambda
e
:
sys
.
stderr
.
write
(
e
+
"
\
n
"
),
lambda
e
:
write
(
sys
.
stderr
,
e
+
"
\
n
"
),
raw_input
)
raw_input
)
if
command
.
execute
()
==
False
:
if
command
.
execute
()
==
False
:
...
...
Utils.py
View file @
ad505816
...
@@ -40,3 +40,8 @@ def convert_todo_number(p_number):
...
@@ -40,3 +40,8 @@ def convert_todo_number(p_number):
def
is_valid_priority
(
p_priority
):
def
is_valid_priority
(
p_priority
):
return
p_priority
!=
None
and
re
.
match
(
r'^[A-Z]$'
,
p_priority
)
!=
None
return
p_priority
!=
None
and
re
.
match
(
r'^[A-Z]$'
,
p_priority
)
!=
None
def
escape_ansi
(
p_string
):
return
escape_ansi
.
pattern
.
sub
(
''
,
p_string
)
escape_ansi
.
pattern
=
re
.
compile
(
r'\x1b[^m]*m'
)
test/CommandTest.py
View file @
ad505816
import
unittest
import
unittest
from
Utils
import
escape_ansi
class
CommandTest
(
unittest
.
TestCase
):
class
CommandTest
(
unittest
.
TestCase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
CommandTest
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
CommandTest
,
self
).
__init__
(
*
args
,
**
kwargs
)
...
@@ -7,7 +9,7 @@ class CommandTest(unittest.TestCase):
...
@@ -7,7 +9,7 @@ class CommandTest(unittest.TestCase):
self
.
errors
=
""
self
.
errors
=
""
def
out
(
self
,
p_output
):
def
out
(
self
,
p_output
):
self
.
output
+=
p_output
+
"
\
n
"
;
self
.
output
+=
escape_ansi
(
p_output
+
"
\
n
"
)
def
error
(
self
,
p_error
):
def
error
(
self
,
p_error
):
self
.
errors
+=
p_error
+
"
\
n
"
;
self
.
errors
+=
escape_ansi
(
p_error
+
"
\
n
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment