Skip to content

Commit

Permalink
Add images support (#6)
Browse files Browse the repository at this point in the history
* Add images support for terminals that support it.
* Add images docs and project screenshot.
* Add features screenshot.
* Make sure that relative paths work for images.
* Use fake backticks in code demo.
  • Loading branch information
rafaelrinaldi committed Apr 27, 2016
1 parent dfc43b5 commit 63b8580
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
43 changes: 37 additions & 6 deletions README.md
@@ -1,7 +1,6 @@
# tslide

Terminal SlideDeck.
(for back end devs)
> Terminal SlideDeck (for back end devs)
---

Expand All @@ -25,15 +24,47 @@ each slide is a section of a markdown document.

## crude js syntax highlighting

``` js
function didItWork() {
```md
# tslide

## Code

//wahey!
‘‘‘js
function fibonacci (n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2)
}
‘‘‘

---
```

![Demo Code](demo-code.png)

This feature is on by default. Disable via `--no-highlight`.

---

# images

[iTerm 2](https://www.iterm2.com) users can
take advantage of [its inline image feature](https://www.iterm2.com/images.html) and use
images in your slides.

```md
# tslide

## Images

![pizza](pizza.png)

There's nothing a pizza can't fix.

---
```

on by default, disable via `--no-highlight`
![Demo Images](demo-images.png)

This feature is on by default. Disable via `--no-images`.

---

Expand Down
Binary file added demo-code.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo-images.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 34 additions & 4 deletions index.js
Expand Up @@ -4,10 +4,12 @@ require('colors')

var charm = require('charm')(process.stdout)
var keypress = require('keypress')(process.stdin)
var opts = require('optimist').argv
var opts = require('optimist').default('images', true).argv
var fs = require('fs')
var path = require('path')
var iq = require('insert-queue')
var js = require('hipster/highlight/javascript')
var imgcat = require('ansi-escapes').image

var file = opts._[0]
var text = require('fs').readFileSync(file, 'utf-8')
Expand All @@ -16,24 +18,52 @@ if(slides.length <= 1) {
console.error('markdown should be split into slides by --- (hdiv)')
process.exit(1)
}
//console.log(slides)
//return

var highlight = opts.highlight !== false

var mleft = 5
var mtop = 2

function images (content) {
var pattern = /^!\[.*?\]\((.*)\)/mg
var notIterm = !/^iterm/i.test(process.env.TERM_PROGRAM)
var match
var image

if (notIterm) {
return content
}

while (match = pattern.exec(content)) {
try {
var url = path.join(__dirname, match[1])

image = imgcat(fs.readFileSync(url))
content = content.replace(match[0], image)
} catch (error) {
// Either file doesn't exist
// or terminal doesn't support images
}
}

return content;
}

function show () {
if(index < 0) index = 0
if(index >= slides.length) index = slides.length - 1

var s = stats(slides[index])
var content = slides[index]

if (opts.images) {
content = images(content)
}

charm
.reset()
.position(1, mtop)
.write(indent(slides[index], mleft))
.write(indent(content, mleft))
.position(mleft, process.stdout.rows - 1)
}
var index = 0
Expand Down
9 changes: 5 additions & 4 deletions package.json
Expand Up @@ -7,14 +7,15 @@
"url": "git://github.com/dominictarr/tslide.git"
},
"dependencies": {
"keypress": "~0.1.0",
"ansi-escapes": "^1.3.0",
"charm": "~0.1.0",
"optimist": "~0.3.4",
"color": "~0.4.1",
"colors": "~0.6.0-1",
"hipster": "~0.9.0",
"insert-queue": "0.0.4",
"colors": "~0.6.0-1",
"markdown-sections": "~1.0.1"
"keypress": "~0.1.0",
"markdown-sections": "~1.0.1",
"optimist": "~0.3.4"
},
"devDependencies": {
"tap": "0.3.0"
Expand Down

0 comments on commit 63b8580

Please sign in to comment.