Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit 19a2cd8c9177b8dcbb8bd2e4da94b2c494a8e83c nddrylliog committed Jun 15, 2010
Showing with 30 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +27 −0 grep.ooc
@@ -0,0 +1,3 @@
+*.swp
+.libs
+grep
@@ -0,0 +1,27 @@
+import io/FileReader, structs/ArrayList, os/Terminal
+
+main: func (args: ArrayList<String>) -> Int {
+
+ if (args size() < 3) {
+ "Usage: %s PATTERN FILE" format(args[0]) println()
+ return -1
+ }
+
+ pattern := args[1]
+ path := args[2]
+
+ FileReader new(path) eachLine(|line|
+ idx := line indexOf(pattern)
+ if(idx != -1) {
+ line[0..idx] print() // before the pattern
+ Terminal setFgColor(Color red). setAttr(Attr bright)
+ pattern print() // the pattern itself
+ Terminal reset()
+ line[(idx + pattern length())..line length()] println() // after the pattern
+ }
+
+ true
+ )
+ 0
+
+}

0 comments on commit 19a2cd8

Please sign in to comment.