Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist shell adapter history between invocations of hubot #800

Merged
merged 26 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1f12647
First pass at readline-history
technicalpickles Oct 21, 2014
d49b131
Add history command
technicalpickles Oct 23, 2014
5e0c98e
Make history size configurable, and default to 1024, for reasons. Als…
technicalpickles Oct 23, 2014
d447398
call @repl.prompt(true) so that that cursor position is preseved afte…
technicalpickles Oct 23, 2014
c10de79
Fix parse help to work synchronously
bouzuya Sep 9, 2014
ac51e29
Fix bug where @pingIntervalId is not being held
rantrix Oct 17, 2014
f82e3d1
Allow preceding whitespace for robot.respond
ahayworth Oct 16, 2014
b7540fc
Fix missing -> in documentation
technicalpickles Oct 23, 2014
7f47af3
Fix incorrect config check option in CHANGELOG.md
MrSaints Oct 26, 2014
55b949d
Fix package.json
technicalpickles Dec 5, 2014
fdf6229
Version bump to 2.9.2
technicalpickles Oct 29, 2014
45d6698
Reduce heroku ping interval down to 5 minutes (from 20)
technicalpickles Oct 29, 2014
d04f02c
Version bump to 2.9.3
technicalpickles Oct 29, 2014
785d826
Don't refer to --create anymore since it's a new generator
technicalpickles Nov 1, 2014
d3868a7
Add contributing header, encourage branching
technicalpickles Nov 1, 2014
3a582cf
More things to do when preparing a pull request
technicalpickles Nov 1, 2014
cbbaed7
Add a releasing section
technicalpickles Nov 1, 2014
febd023
minor spelling fix
Nov 6, 2014
ae5369e
Typo fix EPXRESS_PASSWORD -> EXPRESS_PASSWORD
TheIronMarx Nov 7, 2014
16c9c65
Update README.md
Nov 13, 2014
a4ed69d
added Typetalk adapter to the list of adapters
akiomik Nov 19, 2014
08579ba
Fix typo in robot.respond documentation
stkent Nov 20, 2014
b96067a
Support shell user name and id from the env
Jul 9, 2014
51d5ca8
Add documentation to shell adapter about HUBOT_SHELL_USER_NAME and HU…
technicalpickles Dec 5, 2014
37651c9
Merge master
technicalpickles Dec 5, 2014
c1faced
Fix ENV to env
technicalpickles Dec 5, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,37 @@
"version": "2.9.3",

"author": "hubot",

"keywords": [
"github",
"hubot",
"campfire",
"bot"
],

"description": "A simple helpful robot for your Company",

"licenses": [{
"type": "MIT",
"url": "https://raw.github.com/github/hubot/master/LICENSE"
}],

"repository" : {
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/github/hubot/master/LICENSE"
}
],
"repository": {
"type": "git",
"url": "https://github.com/github/hubot.git"
},

"dependencies": {
"coffee-script": "1.6.3",
"optparse": "1.0.4",
"coffee-script": "1.6.3",
"optparse": "1.0.4",
"scoped-http-client": "0.9.8",
"log": "1.4.0",
"express": "3.18.1"
"log": "1.4.0",
"express": "3.3.4",
"express": "3.18.1",
"readline-history": "~1.2.0"
},

"engines": {
"node": ">= 0.8.x",
"npm": ">= 1.1.x"
"npm": ">= 1.1.x"
},

"main": "./index",

"bin": {
"hubot": "./bin/hubot"
}
Expand Down
52 changes: 35 additions & 17 deletions src/adapters/shell.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Readline = require 'readline'
Readline = require 'readline-history'

Robot = require '../robot'
Adapter = require '../adapter'
{TextMessage} = require '../message'


historySize = if process.env.HUBOT_SHELL_HISTSIZE?
parseInt(process.env.HUBOT_SHELL_HISTSIZE)
else
1024

class Shell extends Adapter
send: (envelope, strings...) ->
unless process.platform is 'win32'
Expand All @@ -20,29 +26,41 @@ class Shell extends Adapter
@send envelope, strings...

run: ->
self = @
stdin = process.openStdin()
stdout = process.stdout

@repl = Readline.createInterface stdin, stdout, null
@repl = null
Readline.createInterface
path: ".hubot_history",
input: stdin,
output: stdout,
maxLength: historySize, # number of entries
next: (rl) =>
@repl = rl
@repl.on 'close', =>
stdin.destroy()
@robot.shutdown()
process.exit 0

@repl.on 'close', =>
stdin.destroy()
@robot.shutdown()
process.exit 0
@repl.on 'line', (buffer) =>

@repl.on 'line', (buffer) =>
@repl.close() if buffer.toLowerCase() is 'exit'
@repl.prompt()
user_id = parseInt(process.env.HUBOT_SHELL_USER_ID or '1')
user_name = process.env.HUBOT_SHELL_USER_NAME or 'Shell'
user = @robot.brain.userForId user_id, name: user_name, room: 'Shell'
@receive new TextMessage user, buffer, 'messageId'
switch buffer.toLowerCase()
when "exit"
@repl.close()
when "history"
stdout.write "#{line}\n" for line in @repl.history
else
user_id = parseInt(process.env.HUBOT_SHELL_USER_ID or '1')
user_name = process.env.HUBOT_SHELL_USER_NAME or 'Shell'
user = @robot.brain.userForId user_id, name: user_name, room: 'Shell'
@receive new TextMessage user, buffer, 'messageId'
@repl.prompt(true)

self.emit 'connected'
@emit 'connected'

@repl.setPrompt "#{@robot.name}> "
@repl.prompt(true)

@repl.setPrompt "#{@robot.name}> "
@repl.prompt()

exports.use = (robot) ->
new Shell robot