def _drawSelectionPanel(self, selection, width, detailPanelHeight, isScrollbarVisible): """ Renders a panel for the selected configuration option. """ # This is a solid border unless the scrollbar is visible, in which case a # 'T' pipe connects the border to the bar. uiTools.drawBox(self, 0, 0, width, detailPanelHeight + 1) if isScrollbarVisible: self.addch(detailPanelHeight, 1, curses.ACS_TTEE) selectionFormat = curses.A_BOLD | uiTools.getColor(CATEGORY_COLOR[selection.get(Field.CATEGORY)]) # first entry: # <option> (<category> Option) optionLabel = " (%s Option)" % selection.get(Field.CATEGORY) self.addstr(1, 2, selection.get(Field.OPTION) + optionLabel, selectionFormat) # second entry: # Value: <value> ([default|custom], <type>, usage: <argument usage>) if detailPanelHeight >= 3: valueAttr = [] valueAttr.append("default" if selection.get(Field.IS_DEFAULT) else "custom") valueAttr.append(selection.get(Field.TYPE)) valueAttr.append("usage: %s" % (selection.get(Field.ARG_USAGE))) valueAttrLabel = ", ".join(valueAttr) valueLabelWidth = width - 12 - len(valueAttrLabel) valueLabel = uiTools.cropStr(selection.get(Field.VALUE), valueLabelWidth) self.addstr(2, 2, "Value: %s (%s)" % (valueLabel, valueAttrLabel), selectionFormat) # remainder is filled with the man page description descriptionHeight = max(0, detailPanelHeight - 3) descriptionContent = "Description: " + selection.get(Field.DESCRIPTION) for i in range(descriptionHeight): # checks if we're done writing the description if not descriptionContent: break # there's a leading indent after the first line if i > 0: descriptionContent = " " + descriptionContent # we only want to work with content up until the next newline if "\n" in descriptionContent: lineContent, descriptionContent = descriptionContent.split("\n", 1) else: lineContent, descriptionContent = descriptionContent, "" if i != descriptionHeight - 1: # there's more lines to display msg, remainder = uiTools.cropStr(lineContent, width - 3, 4, 4, uiTools.Ending.HYPHEN, True) descriptionContent = remainder.strip() + descriptionContent else: # this is the last line, end it with an ellipse msg = uiTools.cropStr(lineContent, width - 3, 4, 4) self.addstr(3 + i, 2, msg, selectionFormat)
def _drawSelectionPanel(self, selection, width, detailPanelHeight, isScrollbarVisible): """ Renders a panel for the selected configuration option. """ # This is a solid border unless the scrollbar is visible, in which case a # 'T' pipe connects the border to the bar. uiTools.drawBox(self, 0, 0, width, detailPanelHeight + 1) if isScrollbarVisible: self.addch(detailPanelHeight, 1, curses.ACS_TTEE) selectionFormat = curses.A_BOLD | uiTools.getColor(CATEGORY_COLOR[selection.get(Field.CATEGORY)]) # first entry: # <option> (<category> Option) optionLabel =" (%s Option)" % selection.get(Field.CATEGORY) self.addstr(1, 2, selection.get(Field.OPTION) + optionLabel, selectionFormat) # second entry: # Value: <value> ([default|custom], <type>, usage: <argument usage>) if detailPanelHeight >= 3: valueAttr = [] valueAttr.append("default" if selection.get(Field.IS_DEFAULT) else "custom") valueAttr.append(selection.get(Field.TYPE)) valueAttr.append("usage: %s" % (selection.get(Field.ARG_USAGE))) valueAttrLabel = ", ".join(valueAttr) valueLabelWidth = width - 12 - len(valueAttrLabel) valueLabel = uiTools.cropStr(selection.get(Field.VALUE), valueLabelWidth) self.addstr(2, 2, "Value: %s (%s)" % (valueLabel, valueAttrLabel), selectionFormat) # remainder is filled with the man page description descriptionHeight = max(0, detailPanelHeight - 3) descriptionContent = "Description: " + selection.get(Field.DESCRIPTION) for i in range(descriptionHeight): # checks if we're done writing the description if not descriptionContent: break # there's a leading indent after the first line if i > 0: descriptionContent = " " + descriptionContent # we only want to work with content up until the next newline if "\n" in descriptionContent: lineContent, descriptionContent = descriptionContent.split("\n", 1) else: lineContent, descriptionContent = descriptionContent, "" if i != descriptionHeight - 1: # there's more lines to display msg, remainder = uiTools.cropStr(lineContent, width - 3, 4, 4, uiTools.Ending.HYPHEN, True) descriptionContent = remainder.strip() + descriptionContent else: # this is the last line, end it with an ellipse msg = uiTools.cropStr(lineContent, width - 3, 4, 4) self.addstr(3 + i, 2, msg, selectionFormat)
def draw(self, width, height): self.valsLock.acquire() # if we don't have any contents then refuse to show details if not self._entries: self._showDetails = False # extra line when showing the detail panel is for the bottom border detailPanelOffset = DETAILS_HEIGHT + 1 if self._showDetails else 0 isScrollbarVisible = len(self._entryLines) > height - detailPanelOffset - 1 scrollLoc = self._scroller.getScrollLoc(self._entryLines, height - detailPanelOffset - 1) cursorSelection = self.getSelection() # draws the detail panel if currently displaying it if self._showDetails and cursorSelection: # This is a solid border unless the scrollbar is visible, in which case a # 'T' pipe connects the border to the bar. uiTools.drawBox(self, 0, 0, width, DETAILS_HEIGHT + 2) if isScrollbarVisible: self.addch(DETAILS_HEIGHT + 1, 1, curses.ACS_TTEE) drawEntries = cursorSelection.getDetails(width) for i in range(min(len(drawEntries), DETAILS_HEIGHT)): self.addstr(1 + i, 2, drawEntries[i][0], drawEntries[i][1]) # title label with connection counts if self.isTitleVisible(): title = "Connection Details:" if self._showDetails else self._title self.addstr(0, 0, title, curses.A_STANDOUT) scrollOffset = 0 if isScrollbarVisible: scrollOffset = 2 self.addScrollBar(scrollLoc, scrollLoc + height - detailPanelOffset - 1, len(self._entryLines), 1 + detailPanelOffset) if self.isPaused() or not self._isTorRunning: currentTime = self.getPauseTime() else: currentTime = time.time() for lineNum in range(scrollLoc, len(self._entryLines)): entryLine = self._entryLines[lineNum] # if this is an unresolved SOCKS, HIDDEN, or CONTROL entry then queue up # resolution for the applicaitions they belong to if isinstance(entryLine, connEntry.ConnectionLine) and entryLine.isUnresolvedApp(): self._resolveApps() # hilighting if this is the selected line extraFormat = curses.A_STANDOUT if entryLine == cursorSelection else curses.A_NORMAL drawLine = lineNum + detailPanelOffset + 1 - scrollLoc prefix = entryLine.getListingPrefix() for i in range(len(prefix)): self.addch(drawLine, scrollOffset + i, prefix[i]) xOffset = scrollOffset + len(prefix) drawEntry = entryLine.getListingEntry(width - scrollOffset - len(prefix), currentTime, self._listingType) for msg, attr in drawEntry: attr |= extraFormat self.addstr(drawLine, xOffset, msg, attr) xOffset += len(msg) if drawLine >= height: break self.valsLock.release()
def draw(self, width, height): self.valsLock.acquire() # if we don't have any contents then refuse to show details if not self._entries: self._showDetails = False # extra line when showing the detail panel is for the bottom border detailPanelOffset = DETAILS_HEIGHT + 1 if self._showDetails else 0 isScrollbarVisible = len( self._entryLines) > height - detailPanelOffset - 1 scrollLoc = self._scroller.getScrollLoc(self._entryLines, height - detailPanelOffset - 1) cursorSelection = self.getSelection() # draws the detail panel if currently displaying it if self._showDetails and cursorSelection: # This is a solid border unless the scrollbar is visible, in which case a # 'T' pipe connects the border to the bar. uiTools.drawBox(self, 0, 0, width, DETAILS_HEIGHT + 2) if isScrollbarVisible: self.addch(DETAILS_HEIGHT + 1, 1, curses.ACS_TTEE) drawEntries = cursorSelection.getDetails(width) for i in range(min(len(drawEntries), DETAILS_HEIGHT)): self.addstr(1 + i, 2, drawEntries[i][0], drawEntries[i][1]) # title label with connection counts if self.isTitleVisible(): title = "Connection Details:" if self._showDetails else self._title self.addstr(0, 0, title, curses.A_STANDOUT) scrollOffset = 0 if isScrollbarVisible: scrollOffset = 2 self.addScrollBar(scrollLoc, scrollLoc + height - detailPanelOffset - 1, len(self._entryLines), 1 + detailPanelOffset) if self.isPaused() or not self._isTorRunning: currentTime = self.getPauseTime() else: currentTime = time.time() for lineNum in range(scrollLoc, len(self._entryLines)): entryLine = self._entryLines[lineNum] # if this is an unresolved SOCKS, HIDDEN, or CONTROL entry then queue up # resolution for the applicaitions they belong to if isinstance( entryLine, connEntry.ConnectionLine) and entryLine.isUnresolvedApp(): self._resolveApps() # hilighting if this is the selected line extraFormat = curses.A_STANDOUT if entryLine == cursorSelection else curses.A_NORMAL drawLine = lineNum + detailPanelOffset + 1 - scrollLoc prefix = entryLine.getListingPrefix() for i in range(len(prefix)): self.addch(drawLine, scrollOffset + i, prefix[i]) xOffset = scrollOffset + len(prefix) drawEntry = entryLine.getListingEntry( width - scrollOffset - len(prefix), currentTime, self.getListingType()) for msg, attr in drawEntry: attr |= extraFormat self.addstr(drawLine, xOffset, msg, attr) xOffset += len(msg) if drawLine >= height: break self.valsLock.release()