Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/sys.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoumith Chintala <soumith@gmail.com>2016-03-31 23:52:50 +0300
committerSoumith Chintala <soumith@gmail.com>2016-03-31 23:52:50 +0300
commiteea341faaa7578936adae14e2a69387230de6194 (patch)
treecf30ea2827df53dc3323eb326ae69763c69509e7
parentcadd701a56dc842b2eab5e6c62126ee4d016244b (diff)
parent6e25ad2dc80ee21ad94ef57ae70cbcb331cf5d1c (diff)
Merge pull request #8 from colesbury/master
Separate sys.COLORS and sys.fpath into their own files
-rw-r--r--CMakeLists.txt2
-rw-r--r--colors.lua32
-rw-r--r--fpath.lua10
-rw-r--r--init.lua35
4 files changed, 46 insertions, 33 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4a6db3..baa0309 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ CMAKE_POLICY(VERSION 2.6)
FIND_PACKAGE(Torch REQUIRED)
SET(src sys.c)
-SET(luasrc init.lua)
+SET(luasrc init.lua colors.lua fpath.lua)
ADD_TORCH_PACKAGE(sys "${src}" "${luasrc}")
diff --git a/colors.lua b/colors.lua
new file mode 100644
index 0000000..f6543e5
--- /dev/null
+++ b/colors.lua
@@ -0,0 +1,32 @@
+--------------------------------------------------------------------------------
+-- colors, can be used to print things in color
+--------------------------------------------------------------------------------
+local colors = {
+ none = '\27[0m',
+ black = '\27[0;30m',
+ red = '\27[0;31m',
+ green = '\27[0;32m',
+ yellow = '\27[0;33m',
+ blue = '\27[0;34m',
+ magenta = '\27[0;35m',
+ cyan = '\27[0;36m',
+ white = '\27[0;37m',
+ Black = '\27[1;30m',
+ Red = '\27[1;31m',
+ Green = '\27[1;32m',
+ Yellow = '\27[1;33m',
+ Blue = '\27[1;34m',
+ Magenta = '\27[1;35m',
+ Cyan = '\27[1;36m',
+ White = '\27[1;37m',
+ _black = '\27[40m',
+ _red = '\27[41m',
+ _green = '\27[42m',
+ _yellow = '\27[43m',
+ _blue = '\27[44m',
+ _magenta = '\27[45m',
+ _cyan = '\27[46m',
+ _white = '\27[47m'
+}
+
+return colors
diff --git a/fpath.lua b/fpath.lua
new file mode 100644
index 0000000..9e4854c
--- /dev/null
+++ b/fpath.lua
@@ -0,0 +1,10 @@
+--------------------------------------------------------------------------------
+-- always returns the path of the file running
+--------------------------------------------------------------------------------
+local function fpath()
+ local fpath = _G.debug.getinfo(2).source:gsub('@','')
+ if fpath:find('/') ~= 1 then fpath = paths.concat(paths.cwd(),fpath) end
+ return paths.dirname(fpath),paths.basename(fpath)
+end
+
+return fpath
diff --git a/init.lua b/init.lua
index 590975f..4596a92 100644
--- a/init.lua
+++ b/init.lua
@@ -78,8 +78,7 @@ function sys.uname()
end
end
end
-local _, os = pcall(sys.uname)
-sys.OS = os
+sys.OS = sys.uname()
--------------------------------------------------------------------------------
-- ls (list dir)
@@ -97,11 +96,7 @@ sys.prefix = execute('which lua'):gsub('//','/'):gsub('/bin/lua\n','')
--------------------------------------------------------------------------------
-- always returns the path of the file running
--------------------------------------------------------------------------------
-function sys.fpath()
- local fpath = _G.debug.getinfo(2).source:gsub('@','')
- if fpath:find('/') ~= 1 then fpath = paths.concat(paths.cwd(),fpath) end
- return paths.dirname(fpath),paths.basename(fpath)
-end
+sys.fpath = require 'sys.fpath'
--------------------------------------------------------------------------------
-- split string based on pattern pat
@@ -143,31 +138,7 @@ end
--------------------------------------------------------------------------------
-- colors, can be used to print things in color
--------------------------------------------------------------------------------
-sys.COLORS = {none = '\27[0m',
- black = '\27[0;30m',
- red = '\27[0;31m',
- green = '\27[0;32m',
- yellow = '\27[0;33m',
- blue = '\27[0;34m',
- magenta = '\27[0;35m',
- cyan = '\27[0;36m',
- white = '\27[0;37m',
- Black = '\27[1;30m',
- Red = '\27[1;31m',
- Green = '\27[1;32m',
- Yellow = '\27[1;33m',
- Blue = '\27[1;34m',
- Magenta = '\27[1;35m',
- Cyan = '\27[1;36m',
- White = '\27[1;37m',
- _black = '\27[40m',
- _red = '\27[41m',
- _green = '\27[42m',
- _yellow = '\27[43m',
- _blue = '\27[44m',
- _magenta = '\27[45m',
- _cyan = '\27[46m',
- _white = '\27[47m'}
+sys.COLORS = require 'sys.colors'
--------------------------------------------------------------------------------
-- backward compat