diff --git a/README.md b/README.md
index 4af54e1..e44f451 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,7 @@ commands however.
* `list` - lists these and other built in commands and aliases.
* `pause` - disables autoscrolling (hit enter on an empty terminal to reenable).
* `reconnect` - reconnects the console to the Screeps server.
+* `shard` - controls the active shards.
* `themes` - lists available themes when called without an argument, or switches.
Otherwise switches themes when called with the theme name as the first
argument.
@@ -110,18 +111,30 @@ Scrolling can be done one line at a time using `alt up` and `alt down`. Using
`PageUp` and `PageDown` (FN+up and FN+down on Apple) can be used to scroll
through the console buffer a bit quicker.
+## Shards
+
+By default all output from all shards is displayed and console commands go to
+shard0. This can be changed with the `shard` commands.
+
+* `shard` - by itself it outputs the shard that console input will go to.
+* `shard SHARDNAME` - changes the shard that console input goes to.
+* `shard focus SHARDNAME` - changes the console output and only displays
+ messages from this shard.
+* `shard clear` - display all output from all shards, but leave the console
+ input pointed at the same shard.
+
## Filters
Console output can be filtered using regular expressions and the `filter`
command. Only commands that match at least one filter will be displayed.
-`filter list` - this lists each current regex filter and its index.
-`filter add REGEX` - add a regular expression to the filter list.
-`filter clear` - remove all filters.
-`filter contains STRING` - add a filter that looks for log lines that contain the
- supplied string.
-`filter remove INDEX` - remove a regular expression using it's index.
+* `filter list` - this lists each current regex filter and its index.
+* `filter add REGEX` - add a regular expression to the filter list.
+* `filter clear` - remove all filters.
+* `filter contains STRING` - add a filter that looks for log lines that contain
+ the supplied string.
+* `filter remove INDEX` - remove a regular expression using it's index.
## Colors and Severity
diff --git a/screeps_console/command.py b/screeps_console/command.py
index 19bc7e3..68c352e 100644
--- a/screeps_console/command.py
+++ b/screeps_console/command.py
@@ -10,6 +10,7 @@
class Processor(object):
+ shard = 'shard0'
lastkey = False
apiclient = False
aliases = {
@@ -118,7 +119,7 @@ def onEnter(self, key):
self.listbox.scrollBottom()
userInput.set_edit_text('')
apiclient = self.getApiClient()
- apiclient.console(user_text)
+ apiclient.console(user_text, self.shard)
def onTab(self, key):
self.autocomplete.complete()
@@ -266,6 +267,36 @@ def reconnect(self, comp):
comp.listwalker.append(urwid.Text(('logged_response', 'reconnecting')))
comp.listbox.autoscroll()
+ def shard(self, comp):
+ userInput = comp.edit
+ user_text = userInput.get_edit_text()
+ user_command_split = user_text.split(' ')
+
+ if len(user_command_split) < 2 or user_command_split[1] == 'current':
+ comp.listwalker.appendText(comp.shard)
+ return
+
+ if user_command_split[1] == 'clear':
+ comp.consolemonitor.focus = False
+ comp.listwalker.appendText('Clearing shard settings')
+ return
+
+ if user_command_split[1] == 'focus':
+ if len(user_command_split) < 3:
+ comp.consolemonitor.focus = False
+ comp.listwalker.appendText('Disabled shard focus')
+ else:
+ shard = user_command_split[2]
+ comp.consolemonitor.focus = shard
+ comp.shard = shard
+ message = 'Enabled shard focus on %s' % (shard)
+ comp.listwalker.appendText(message)
+ return
+
+ comp.shard = user_command_split[1]
+ response = 'Setting active shard to %s' % (comp.shard,)
+ comp.listwalker.appendText(response)
+
def themes(self, comp):
userInput = comp.edit
user_text = userInput.get_edit_text()
@@ -277,7 +308,7 @@ def themes(self, comp):
for theme in theme_names:
theme_list = theme + ' ' + theme_list
- comp.listwalker.append(urwid.Text(('logged_response', theme_list)))
+ comp.listwalker.appendText(theme_list)
return
if user_command_split[1] == 'test':
@@ -323,8 +354,8 @@ def turtle(self, comp):
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)
'''
- comp.listwalker.append(urwid.Text(('logged_response', turtle)))
- comp.listwalker.append(urwid.Text(('logged_response', '')))
+ comp.listwalker.appendText(turtle)
+ comp.listwalker.appendText('')
def whoami(self, comp):
me = comp.getApiClient().me()['username']
diff --git a/screeps_console/console.py b/screeps_console/console.py
index 2392add..60a39ee 100755
--- a/screeps_console/console.py
+++ b/screeps_console/console.py
@@ -46,6 +46,12 @@ def on_message(self, ws, message):
data = json.loads(message)
+ if 'shard' in data[1]:
+ shard = data[1]['shard']
+ else:
+ shard = 'shard0'
+
+
if 'messages' in data[1]:
stream = []
@@ -57,7 +63,6 @@ def on_message(self, ws, message):
results = map(lambda x:''+x+'',results)
stream = stream + results
-
message_count = len(stream)
if message_count > 0:
@@ -71,11 +76,11 @@ def on_message(self, ws, message):
for line in stream:
if self.format == 'color':
- line_parsed = parseLine(line)
+ line_parsed = '%s: %s' % (shard, parseLine(line))
elif self.format == 'json':
- line_parsed = json.dumps(line)
+ line_parsed = json.dumps({'line':line,'shard':shard})
else:
- line_parsed = tagLine(line)
+ line_parsed = '%s: %s' % (shard, tagLine(line))
print line_parsed
sys.stdout.flush()
@@ -86,11 +91,11 @@ def on_message(self, ws, message):
#line = '<'+data[1]['error']
line = "" + data[1]['error'] + ""
if self.format == 'color':
- line_parsed = parseLine(line)
+ line_parsed = '%s: %s' % (shard, parseLine(line))
elif self.format == 'json':
- line_parsed = json.dumps(line)
+ line_parsed = json.dumps({'line':line,'shard':shard})
else:
- line_parsed = tagLine(line)
+ line_parsed = '%s: %s' % (shard, tagLine(line))
print line_parsed
return
diff --git a/screeps_console/interactive.py b/screeps_console/interactive.py
index 49fa10b..89d7c6b 100755
--- a/screeps_console/interactive.py
+++ b/screeps_console/interactive.py
@@ -126,6 +126,10 @@ def scrollDown(self, quantity):
class consoleWalker(urwid.SimpleListWalker):
+
+ def appendText(self, message, format='logged_response'):
+ self.append(urwid.Text((format, message)))
+
def append(self, value):
if(len(self) >= self.max_buffer):
self.pop(0)
@@ -234,6 +238,7 @@ class ScreepsConsoleMonitor:
proc = False
quiet = False
+ focus = False
filters = []
def __init__(self, widget, walker, loop):
@@ -293,9 +298,16 @@ def onUpdate(self, data):
if len(line_json) <= 0:
continue
try:
- line = json.loads(line_json.strip())
+ line_data = json.loads(line_json.strip())
+ line = line_data['line']
+ shard = line_data['shard']
+
+ if self.focus and self.focus != line_data['shard']:
+ continue
+
+
except:
- print line_json
+ print line_json
logging.exception('error processing data: ' + line_json)
continue
@@ -339,7 +351,7 @@ def onUpdate(self, data):
if not has_match:
continue
- self.walker.append(urwid.Text((formatting, line)))
+ self.walker.append(urwid.Text((formatting, '%s: %s' % (shard, line))))
self.widget.autoscroll()
except: