about summary refs log tree commit diff stats
path: root/054string-equal.subx
Commit message (Collapse)AuthorAgeFilesLines
* 6182 - start of support for safe handlesKartik Agaram2020-04-031-14/+14
| | | | | | | | | | | | | | So far it's unclear how to do this in a series of small commits. Still nibbling around the edges. In this commit we standardize some terminology: The length of an array or stream is denominated in the high-level elements. The _size_ is denominated in bytes. The thing we encode into the type is always the size, not the length. There's still an open question of what to do about the Mu `length` operator. I'd like to modify it to provide the length. Currently it provides the size. If I can't fix that I'll rename it.
* 6178Kartik Agaram2020-03-311-1/+1
|
* 5948 - branching to named blocksKartik Agaram2020-01-291-19/+61
|
* 5924Kartik Agaram2020-01-271-8/+8
|
* 5897 - rename comparison instructionsKartik Agaram2020-01-161-3/+3
| | | | | | | Signed and unsigned don't quite capture the essence of what the different combinations of x86 flags are doing for SubX. The crucial distinction is that one set of comparison operators is for integers and the second is for addresses.
* 5876 - address -> addrKartik Agaram2020-01-031-5/+5
|
* 5804Kartik Agaram2019-12-081-8/+9
| | | | | Try to make the comments consistent with the type system we'll eventually have.
* 5792Kartik Agaram2019-12-051-9/+0
| | | | | Fix a bug in one test: it checks eax when the component under test returns nothing. It's been just accidentally passing all these months.
* 5778Kartik Agaram2019-11-291-6/+6
|
* 5698Kartik Agaram2019-10-151-4/+4
| | | | Thanks Andrew Owen for reporting this typo.
* 5592 - switch register names to lowercaseKartik Agaram2019-08-261-83/+83
|
* 5485 - promote SubX to top-levelKartik Agaram2019-07-271-0/+230
{ color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
"""The TitleBar widget displays the current path and some other useful
information."""

from . import Widget
from ranger import log
from math import floor

class TitleBar(Widget):
	old_cf = None
	old_keybuffer = None
	old_wid = None
	result = None
	throbber = ' '

	def draw(self):
		if self.env.cf != self.old_cf or\
				str(self.env.keybuffer) != str(self.old_keybuffer) or\
				self.wid != self.old_wid:
			self.old_wid = self.wid
			self.old_cf = self.env.cf
			self._calc_bar()
		self._print_result(self.result)
		if self.wid > 2:
			self.color('in_titlebar', 'throbber')
			self.win.addnstr(self.y, self.wid - 2, self.throbber, 1)

	def _calc_bar(self):
		bar = Bar()
		self._get_left_part(bar)
		self._get_right_part(bar)
		try:
			bar.shrink_by_cutting(self.wid)
		except ValueError:
			bar.shrink_by_removing(self.wid)
		self.result = bar.combine()
	
	def _get_left_part(self, bar):
		import socket, os
		
		bar.add(os.getenv('LOGNAME'), 'hostname', fixedsize=True)
		bar.add('@', 'hostname', fixedsize=True)
		bar.add(socket.gethostname(), 'hostname', fixedsize=True)

		for path in self.env.pathway:
			if path.islink:
				clr = 'link'
			else:
				clr = 'directory'

			bar.add(path.basename, clr)
			bar.add('/', clr, fixedsize=True)

		if self.env.cf is not None:
			bar.add(self.env.cf.basename, 'file', fixedsize=True)

	def _get_right_part(self, bar):
		kb = str(self.env.keybuffer)
		self.old_keybuffer = kb
		bar.addright(kb, 'keybuffer', fixedsize=True)
		bar.addright('  ', 'space', fixedsize=True)

	def _print_result(self, result):
		import _curses
		self.win.move(self.y, self.x)
		for part in result:
			self.color(*part.lst)
			try:
				self.win.addstr(part.string)
			except _curses.error:
				pass
		self.color_reset()


class Bar(object):
	left = None
	right = None
	gap = None

	def __init__(self):
		self.left = BarSide()
		self.right = BarSide()
		self.gap = BarSide()

	def add(self, *a, **kw):
		self.left.add(*a, **kw)
	
	def addright(self, *a, **kw):
		self.right.add(*a, **kw)

	def sumsize(self):
		return self.left.sumsize() + self.right.sumsize()

	def fixedsize(self):
		return self.left.fixedsize() + self.right.fixedsize()

	def shrink_by_removing(self, wid):
		leftsize = self.left.sumsize()
		rightsize = self.right.sumsize()
		sumsize = leftsize + rightsize

		# remove elemets from the left until it fits
		if sumsize > wid:
			while len(self.left) > 0:
				leftsize -= len(self.left.pop(-1).string)
				if leftsize + rightsize <= wid:
					break
			sumsize = leftsize + rightsize

			# remove elemets from the right until it fits
			if sumsize > wid:
				while len(self.right) > 0:
					rightsize -= len(self.right.pop(0).string)
					if leftsize + rightsize <= wid:
						break
				sumsize = leftsize + rightsize

		if sumsize < wid:
			self.fill_gap(' ', (wid - sumsize), gapwidth=True)
	
	def shrink_by_cutting(self, wid):
		fixedsize = self.fixedsize()
		if wid < fixedsize:
			raise ValueError("Cannot shrink down to that size by cutting")

		leftsize = self.left.sumsize()
		rightsize = self.right.sumsize()
		nonfixed_items = self.left.nonfixed_items()

#		log(leftsize, fixedsize, nonfixed_items)
		itemsize = int(float(wid - rightsize - fixedsize) / nonfixed_items) + 1
#		log(itemsize)

		for item in self.left:
			if not item.fixed:
				item.cut_off_to(itemsize)

		self.fill_gap(' ', wid, gapwidth=False)

	def fill_gap(self, char, wid, gapwidth=False):
		del self.gap[:]

		if not gapwidth:
			wid = wid - self.sumsize()

		if wid > 0:
			self.gap.add(char * wid, 'space')
	
	def combine(self):
		return self.left + self.gap + self.right


class BarSide(list):
	def add(self, string, *lst, **kw):
		cs = ColoredString(string, 'in_titlebar', *lst)
		if 'fixedsize' in kw:
			cs.fixed = kw['fixedsize']
		self.append(cs)
	
	def sumsize(self):
		return sum(len(item) for item in self)

	def fixedsize(self):
		n = 0
		for item in self:
			if item.fixed:
				n += len(item)
			else:
				n += 1
		return n
	
	def nonfixed_items(self):
		return sum(1 for item in self if not item.fixed)


class ColoredString(object):
	fixed = False

	def __init__(self, string, *lst):
		self.string = string
		self.lst = lst
	
	def cut_off(self, n):
		n = max(n, min(len(self.string), 1))
		self.string = self.string[:-n]

	def cut_off_to(self, n):
		self.string = self.string[:n]
	
	def __len__(self):
		return len(self.string)

	def __str__(self):
		return self.string