Ejemplo n.º 1
0
	def get_segments(self, side=None, line=0, segment_info=None, mode=None):
		'''Return all segments.

		Function segments are called, and all segments get their before/after
		and ljust/rjust properties applied.

		:param int line:
			Line number for which segments should be obtained. Is counted from 
			zero (botmost line).
		'''
		for side in [side] if side else ['left', 'right']:
			parsed_segments = []
			for segment in self.segments[line][side]:
				# No segment-local modes at this point
				if mode not in segment['exclude_modes'] and (
					not segment['include_modes'] or mode in segment['include_modes']
				):
					process_segment(self.pl, side, segment_info, parsed_segments, segment, mode)
			for segment in parsed_segments:
				segment['contents'] = segment['before'] + u(segment['contents'] if segment['contents'] is not None else '') + segment['after']
				# Align segment contents
				if segment['width'] and segment['width'] != 'auto':
					if segment['align'] == 'l':
						segment['contents'] = segment['contents'].ljust(segment['width'])
					elif segment['align'] == 'r':
						segment['contents'] = segment['contents'].rjust(segment['width'])
					elif segment['align'] == 'c':
						segment['contents'] = segment['contents'].center(segment['width'])
				# We need to yield a copy of the segment, or else mode-dependent
				# segment contents can't be cached correctly e.g. when caching
				# non-current window contents for vim statuslines
				yield segment.copy()
Ejemplo n.º 2
0
	def get_segments(self, side=None, line=0, segment_info=None, mode=None):
		'''Return all segments.

		Function segments are called, and all segments get their before/after
		and ljust/rjust properties applied.

		:param int line:
			Line number for which segments should be obtained. Is counted from 
			zero (botmost line).
		'''
		for side in [side] if side else ['left', 'right']:
			parsed_segments = []
			for segment in self.segments[line][side]:
				if segment['display_condition'](self.pl, segment_info, mode):
					process_segment(
						self.pl,
						side,
						segment_info,
						parsed_segments,
						segment,
						mode,
						self.colorscheme,
					)
			for segment in parsed_segments:
				self.pl.prefix = segment['name']
				try:
					width = segment['width']
					align = segment['align']
					if width == 'auto' and segment['expand'] is None:
						segment['expand'] = expand_functions.get(align)
						if segment['expand'] is None:
							self.pl.error('Align argument must be “r”, “l” or “c”, not “{0}”', align)

					try:
						segment['contents'] = segment['before'] + u(
							segment['contents'] if segment['contents'] is not None else ''
						) + segment['after']
					except Exception as e:
						self.pl.exception('Failed to compute segment contents: {0}', str(e))
						segment['contents'] = safe_unicode(segment.get('contents'))
					# Align segment contents
					if segment['width'] and segment['width'] != 'auto':
						if segment['align'] == 'l':
							segment['contents'] = segment['contents'].ljust(segment['width'])
						elif segment['align'] == 'r':
							segment['contents'] = segment['contents'].rjust(segment['width'])
						elif segment['align'] == 'c':
							segment['contents'] = segment['contents'].center(segment['width'])
					# We need to yield a copy of the segment, or else mode-dependent
					# segment contents can’t be cached correctly e.g. when caching
					# non-current window contents for vim statuslines
					yield segment.copy()
				except Exception as e:
					self.pl.exception('Failed to compute segment: {0}', str(e))
					fallback = get_fallback_segment()
					fallback.update(side=side)
					yield fallback
Ejemplo n.º 3
0
	def get_segments(self, side=None, line=0, segment_info=None, mode=None):
		'''Return all segments.

		Function segments are called, and all segments get their before/after
		and ljust/rjust properties applied.

		:param int line:
			Line number for which segments should be obtained. Is counted from 
			zero (botmost line).
		'''
		for side in [side] if side else ['left', 'right']:
			parsed_segments = []
			for segment in self.segments[line][side]:
				if segment['display_condition'](self.pl, segment_info, mode):
					process_segment(
						self.pl,
						side,
						segment_info,
						parsed_segments,
						segment,
						mode,
						self.colorscheme,
					)
			for segment in parsed_segments:
				self.pl.prefix = segment['name']
				try:
					width = segment['width']
					align = segment['align']
					if width == 'auto' and segment['expand'] is None:
						segment['expand'] = expand_functions.get(align)
						if segment['expand'] is None:
							self.pl.error('Align argument must be “r”, “l” or “c”, not “{0}”', align)

					try:
						segment['contents'] = segment['before'] + u(
							segment['contents'] if segment['contents'] is not None else ''
						) + segment['after']
					except Exception as e:
						self.pl.exception('Failed to compute segment contents: {0}', str(e))
						segment['contents'] = safe_unicode(segment.get('contents'))
					# Align segment contents
					if segment['width'] and segment['width'] != 'auto':
						if segment['align'] == 'l':
							segment['contents'] = segment['contents'].ljust(segment['width'])
						elif segment['align'] == 'r':
							segment['contents'] = segment['contents'].rjust(segment['width'])
						elif segment['align'] == 'c':
							segment['contents'] = segment['contents'].center(segment['width'])
					# We need to yield a copy of the segment, or else mode-dependent
					# segment contents can’t be cached correctly e.g. when caching
					# non-current window contents for vim statuslines
					yield segment.copy()
				except Exception as e:
					self.pl.exception('Failed to compute segment: {0}', str(e))
					fallback = get_fallback_segment()
					fallback.update(side=side)
					yield fallback
Ejemplo n.º 4
0
    def get_segments(self, side=None, line=0, segment_info=None, mode=None):
        '''Return all segments.

		Function segments are called, and all segments get their before/after
		and ljust/rjust properties applied.

		:param int line:
			Line number for which segments should be obtained. Is counted from 
			zero (botmost line).
		'''
        for side in [side] if side else ['left', 'right']:
            parsed_segments = []
            for segment in self.segments[line][side]:
                # No segment-local modes at this point
                if mode not in segment['exclude_modes'] and (
                        not segment['include_modes']
                        or mode in segment['include_modes']):
                    process_segment(self.pl, side, segment_info,
                                    parsed_segments, segment, mode)
            for segment in parsed_segments:
                segment['contents'] = segment['before'] + u(
                    segment['contents'] if segment['contents'] is not None else
                    '') + segment['after']
                # Align segment contents
                if segment['width'] and segment['width'] != 'auto':
                    if segment['align'] == 'l':
                        segment['contents'] = segment['contents'].ljust(
                            segment['width'])
                    elif segment['align'] == 'r':
                        segment['contents'] = segment['contents'].rjust(
                            segment['width'])
                    elif segment['align'] == 'c':
                        segment['contents'] = segment['contents'].center(
                            segment['width'])
                # We need to yield a copy of the segment, or else mode-dependent
                # segment contents can't be cached correctly e.g. when caching
                # non-current window contents for vim statuslines
                yield segment.copy()