summary refs log tree commit diff stats
path: root/ranger/shared/settings.py
blob: 552154cd2a4f002ba6ce6691ae6fc62d69588108 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

ALLOWED_SETTINGS = """
show_hidden scroll_offset
directories_first sort reverse
preview_files max_history_size colorscheme
collapse_preview
hidden_filter
max_dirsize_for_autopreview autosave_bookmarks
apps keys
""".split()

# -- globalize the settings --

from ranger.ext.openstruct import OpenStruct
class SettingsAware(object):
	settings = OpenStruct()

	@staticmethod
	def _setup():
		from inspect import isclass, ismodule
		from ranger.gui.colorscheme import ColorScheme

		# overwrite single default options with custom options
		from ranger.defaults import options
		try:
			import options as custom_options
			for setting in ALLOWED_SETTINGS:
				if hasattr(custom_options, setting):
					setattr(options, setting, getattr(custom_options, setting))
				elif not hasattr(options, setting):
					raise Exception("Following option was not defined: " + setting)
		except ImportError:
			pass

		# If a module is specified as the colorscheme, replace it with one
		# valid colorscheme inside that module.

		if isclass(options.colorscheme) and \
				issubclass(options.colorscheme, ColorScheme):
			options.colorscheme = options.colorscheme()

		elif ismodule(options.colorscheme):
			for var_name in dir(options.colorscheme):
				var = getattr(options.colorscheme, var_name)
				if var != ColorScheme and isclass(var) \
						and issubclass(var, ColorScheme):
					options.colorscheme = var()
					break
			else:
				raise Exception("The module contains no valid colorscheme!")

		else:
			raise Exception("Cannot locate colorscheme!")

		for setting in ALLOWED_SETTINGS:
			SettingsAware.settings[setting] = getattr(options, setting)
ptato <nincsnevem662@gmail.com> 2024-01-29 15:58:58 +0100 layout: consider inline positioning for absolute blocks' href='/ahoang/chawan/commit/src/layout/box.nim?id=69ab68942e73458a1b0105d16bc5cb1210895f29'>69ab6894 ^
04403976 ^
39e2ef52 ^





062027c8 ^
9fdea97d ^
7146419b ^
062027c8 ^
ca5aea89 ^
616e60b7 ^
39e2ef52 ^

32a94cec ^


1c6ce089 ^
95c5438a ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
                     
                 
                        

    
                  



                  

                  
 
                        
                                       

                          
                   

                           
                  
             
               
                  
                      
                         
 

                                  
                   

                             



                                    


                           
 


                            

                   
               



                                                                           



                                  
                              
 





                        
                                   
                               
                     
                          
                                
                   

                                                


                                                                           
                          



                                                       
import css/stylednode
import css/values
import layout/layoutunit

type
  Offset* = object
    x*: LayoutUnit
    y*: LayoutUnit

  Size* = object
    w*: LayoutUnit
    h*: LayoutUnit

  InlineAtomType* = enum
    iatSpacing, iatWord, iatInlineBlock

  InlineAtom* = ref object
    offset*: Offset
    size*: Size
    case t*: InlineAtomType
    of iatSpacing:
      discard
    of iatWord:
      str*: string
    of iatInlineBlock:
      innerbox*: BlockBox

  RootInlineFragment* = ref object
    # offset relative to parent
    offset*: Offset
    # root fragment
    fragment*: InlineFragment
    # baseline of the first line box
    firstBaseline*: LayoutUnit
    # baseline of the last line box
    baseline*: LayoutUnit
    # minimum content width
    xminwidth*: LayoutUnit
    size*: Size

  SplitType* = enum
    stSplitStart, stSplitEnd

  Area* = object
    offset*: Offset
    size*: Size

  InlineFragment* = ref object
    startOffset*: Offset # offset of the first word, for position: absolute
    areas*: seq[Area] # background that should be painted by fragment
    children*: seq[InlineFragment]
    atoms*: seq[InlineAtom]
    computed*: CSSComputedValues
    node*: StyledNode
    splitType*: set[SplitType]

  RelativeRect* = object
    top*: LayoutUnit
    bottom*: LayoutUnit
    left*: LayoutUnit
    right*: LayoutUnit

  BlockBox* = ref object of RootObj
    inline*: RootInlineFragment
    node*: StyledNode
    nested*: seq[BlockBox]
    computed*: CSSComputedValues
    offset*: Offset
    size*: Size # padding size
    margin*: RelativeRect #TODO get rid of this?
    # very bad name. basically the minimum content width after the contents
    # have been positioned (usually the width of the shortest word.) used
    # in table cells.
    xminwidth*: LayoutUnit
    # baseline of the first line box of all descendants
    firstBaseline*: LayoutUnit
    # baseline of the last line box of all descendants
    baseline*: LayoutUnit