about summary refs log tree commit diff stats
path: root/310copy-bytes.subx
blob: 2586a53fe4dab6af58a7d71eed2f303eadcd8aac (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Some helpers for copying non-overlapping regions of memory.
# Really only intended to be called from code generated by mu.subx.

== code

copy-bytes:  # src: (addr byte), dest: (addr byte), size: int
    # pseudocode:
    #   curr-src/esi = src
    #   curr-dest/edi = dest
    #   i/ecx = 0
    #   while true
    #     if (i >= size) break
    #     *curr-dest = *curr-src
    #     ++curr-src
    #     ++curr-dest
    #     ++i
    #
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    51/push-ecx
    52/push-edx
    56/push-esi
    57/push-edi
    # curr-src/esi = src
    8b/-> *(ebp+8) 6/r32/esi
    # curr-dest/edi = dest
    8b/-> *(ebp+0xc) 7/r32/edi
    # var i/ecx: int = 0
    b9/copy-to-ecx 0/imm32
    # edx = size
    8b/-> *(ebp+0x10) 2/r32/edx
    {
      # if (i >= size) break
      39/compare %ecx 2/r32/edx
      7d/jump-if->=  break/disp8
      # *curr-dest = *curr-src
      8a/byte-> *esi 0/r32/AL
      88/byte<- *edi 0/r32/AL
      # update
      46/increment-esi
      47/increment-edi
      41/increment-ecx
      eb/jump loop/disp8
    }
$copy-bytes:end:
    # . restore registers
    5f/pop-to-edi
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

stream-to-array:  # in: (addr stream _), out: (addr handle array _)
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = s
    8b/-> *(ebp+8) 6/r32/esi
    # var len/ecx: int = s->write - s->read
    8b/-> *esi 1/r32/ecx
    2b/subtract *(esi+4) 1/r32/ecx
    # allocate
    (allocate-array Heap %ecx *(ebp+0xc))
    # var in/edx: (addr byte) = s->data + s->read
    8b/-> *(esi+4) 2/r32/edx
    8d/copy-address *(esi+edx+0xc) 2/r32/edx
    # var dest/eax: (addr byte) = data for out
    8b/-> *(ebp+0xc) 0/r32/eax
    (lookup *eax *(eax+4))  # => eax
    8d/copy-address *(eax+4) 0/r32/eax
    #
    (copy-bytes %edx %eax %ecx)
$stream-to-array:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

test-stream-to-array:
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # setup
    (clear-stream _test-input-stream)
    (write _test-input-stream "abc")
    # skip something
    (read-byte _test-input-stream)  # => eax
    # var out/ecx: (handle array byte)
    68/push 0/imm32
    68/push 0/imm32
    89/<- %ecx 4/r32/esp
    #
    (stream-to-array _test-input-stream %ecx)
    (lookup *ecx *(ecx+4))  # => eax
    (check-strings-equal %eax "bc")
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

# like stream-to-array but ignore surrounding quotes
# we might do other stuff here later
unquote-stream-to-array:  # in: (addr stream _), out: (addr handle array _)
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    51/push-ecx
    52/push-edx
    56/push-esi
    # esi = s
    8b/-> *(ebp+8) 6/r32/esi
    # var len/ecx: int = s->write - s->read - 2
    8b/-> *esi 1/r32/ecx
    2b/subtract *(esi+4) 1/r32/ecx
    81 7/subop/compare %ecx 2/imm32
    7c/jump-if-< $unquote-stream-to-array:end/disp8
    81 5/subop/subtract %ecx 2/imm32
    # allocate
    (allocate-array Heap %ecx *(ebp+0xc))
    # var in/edx: (addr byte) = s->data + s->read + 1
    8b/-> *(esi+4) 2/r32/edx
    8d/copy-address *(esi+edx+0xd) 2/r32/edx  # Stream-data + 1
    # var dest/eax: (addr byte) = data for out
    8b/-> *(ebp+0xc) 0/r32/eax
    (lookup *eax *(eax+4))  # => eax
    8d/copy-address *(eax+4) 0/r32/eax
    #
    (copy-bytes %edx %eax %ecx)
$unquote-stream-to-array:end:
    # . restore registers
    5e/pop-to-esi
    5a/pop-to-edx
    59/pop-to-ecx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return
pager' href='/akspecs/ranger/commit/ranger/gui/defaultui.py?id=06aefcf5068e733f22251894306c2818860bf255'>06aefcf5 ^
d88232a3 ^

1159f9ec ^
49ae0dd1 ^
9506fb8e ^
6f43de0a ^


d88232a3 ^
cfdbb9d6 ^

a923ead7 ^
6f43de0a ^

e6dfc442 ^
06aefcf5 ^
5715beca ^

06aefcf5 ^

8db3c4b1 ^
06aefcf5 ^

5715beca ^

06aefcf5 ^

8db3c4b1 ^
5715beca ^
06aefcf5 ^

8db3c4b1 ^

06aefcf5 ^

8db3c4b1 ^
06aefcf5 ^
7ec262f8 ^

e6dfc442 ^

cfdbb9d6 ^
e6dfc442 ^


cfdbb9d6 ^
5715beca ^
e6dfc442 ^
b5393406 ^
8db3c4b1 ^
b5393406 ^

ddf828fb ^
b5393406 ^

8db3c4b1 ^
b5393406 ^
ddf828fb ^
e6dfc442 ^
8db3c4b1 ^

633387ba ^
9a78b644 ^




a396b3a0 ^

6f43de0a ^
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
 
                       
 

                            
                        
                                                              
                                                                      

                                                                
                                                                  
                                                                

                                                          
                                    
                                                  
                                             
 



                                                           
 
                                            


                                                  
 
                                       
                                                                           


                                           
                                                
                                            

                                            
                                  
                                            
                                          
                                          
 

                                        
                                    
                                        
 


                                                    
                                                

                                                   
        

                                                  
 
                              

                                                   

                                          
                                           

                             

                                                    

                                         
                                            
                                 

                                      

                                         

                                       
                                          
        

                                                   

                                                                  
                                                   


                                            
                                          
                                  
 
                                
                                            

                                            
 

                                             
                                           
                                             
 
                                   

                                                                 
        




                                                                             

                                  
                                       
RATIO = ( 3, 3, 12, 9 )

from ranger.gui.ui import UI
class DefaultUI(UI):
	def setup(self):
		"""Build up the UI by initializing widgets."""
		from ranger.gui.widgets.browserview import BrowserView
		from ranger.gui.widgets.titlebar import TitleBar
		from ranger.gui.widgets.console import Console
		from ranger.gui.widgets.statusbar import StatusBar
		from ranger.gui.widgets.taskview import TaskView
		from ranger.gui.widgets.pager import Pager

		# Create a title bar
		self.titlebar = TitleBar(self.win)
		self.add_child(self.titlebar)

		# Create the browser view
		self.browser = BrowserView(self.win, RATIO)
		self.add_child(self.browser)
		self.main_column = self.browser.main_column

		# Create the process manager
		self.taskview = TaskView(self.win)
		self.taskview.visible = False
		self.add_child(self.taskview)

		# Create the status bar
		self.status = StatusBar(self.win, self.browser.main_column)
		self.add_child(self.status)

		# Create the console
		self.console = Console(self.win)
		self.add_child(self.console)
		self.console.visible = False

		# Create the pager
		self.pager = Pager(self.win)
		self.pager.visible = False
		self.add_child(self.pager)

	def update_size(self):
		"""resize all widgets"""
		UI.update_size(self)
		y, x = self.env.termsize

		self.browser.resize(1, 0, y - 2, x)
		self.taskview.resize(1, 0, y - 2, x)
		self.pager.resize(1, 0, y - 2, x)
		self.titlebar.resize(0, 0, 1, x)
		self.status.resize(y - 1, 0, 1, x)
		self.console.resize(y - 1, 0, 1, x)
	
	def notify(self, *a, **k):
		return self.status.notify(*a, **k)

	def close_pager(self):
		if self.console.visible:
			self.console.focused = True
		self.pager.visible = False
		self.pager.focused = False
		self.browser.visible = True
	
	def open_pager(self):
		if self.console.focused:
			self.console.focused = False
		self.pager.visible = True
		self.pager.focused = True
		self.browser.visible = False
		return self.pager

	def open_embedded_pager(self):
		self.browser.open_pager()
		return self.browser.pager

	def close_embedded_pager(self):
		self.browser.close_pager()
	
	def open_console(self, mode, string=''):
		if self.console.open(mode, string):
			self.console.on_close = self.close_console
			self.console.visible = True
			self.status.visible = False

	def close_console(self):
		self.console.visible = False
		self.status.visible = True
		self.close_pager()

	def open_taskview(self):
		self.browser.visible = False
		self.taskview.visible = True
		self.taskview.focused = True

	def close_taskview(self):
		self.taskview.visible = False
		self.browser.visible = True
		self.taskview.focused = False

	def scroll(self, relative):
		if self.browser and self.browser.main_column:
			self.browser.main_column.scroll(relative)
	
	def throbber(self, string='.', remove=False):
		if remove:
			self.titlebar.throbber = type(self.titlebar).throbber
		else:
			self.titlebar.throbber = string

	def hint(self, text=None):
		self.status.hint = text