summary refs log tree commit diff stats
path: root/tests/errmsgs
Commit message (Expand)AuthorAgeFilesLines
* fixes #6499; disallow built-in procs used as procvars (#22291)ringabout2023-07-191-0/+6
* fixes #22049; fixes #22054; implicit conversion keeps varness (#22097)ringabout2023-06-161-0/+9
* some test cleanups & category reorganization (#22010)metagn2023-06-067-0/+59
* properly disallow unresolved generic proc values (#22005)metagn2023-06-051-0/+10
* clean up SOME pending/xxx/issue link comments (#21826)metagn2023-05-111-22/+6
* cheap fix for #10853 + better tuple subscript error message (#21767)metagn2023-05-022-0/+5
* alias syntax fixes, improvements and tests (#21671)metagn2023-04-221-10/+10
* make --exceptions:quirky work with C++ (#21581)Andreas Rumpf2023-03-311-1/+1
* hopefully easier to understand error message (#21585)Andreas Rumpf2023-03-301-2/+2
* closes #16654; add a test case (#21478)ringabout2023-03-061-0/+12
* tests/errmsgs/tcall_with_default_arg.nim: sync (#21237)Anna2023-03-011-1/+1
* tests: explicitly enable stack traces where needed (#21236)Anna2023-03-013-17/+20
* fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now pa...ringabout2023-02-221-3/+5
* close #21257 (#21275)metagn2023-01-181-0/+20
* fixes #21195; `std/assertions` continue to use `sysFatal` when `nimPreviewSli...ringabout2022-12-291-2/+2
* fixes #14444; add `genLineDir` before assignment (#21201)ringabout2022-12-291-0/+14
* less verbose type mismatch messages (#21191)ringabout2022-12-282-0/+44
* fix for bad error message with const in case statement (#21182)metagn2022-12-271-0/+7
* Named arguments in commands + many grammar fixes (#20994)metagn2022-12-062-3/+3
* revert #20719; relieve `std/assertions` of the `sysFatal` dep (#20743)ringabout2022-11-041-4/+5
* fix semcase on tySequence and tyObject #20283 #19682 (#20339)Bung2022-11-011-0/+29
* 'lock levels' are deprecated, now a noop (#20539)ringabout2022-10-119-42/+39
* fix #18886 crash on ambiguous proc cast (#20472)Bung2022-10-101-0/+18
* add default field support for object in ARC/ORC (#20480)ringabout2022-10-041-1/+1
* fixes nim check with orc (#20456)ringabout2022-10-021-1/+1
* Fix #19224 For loops over a hardcoded empty array crash the compiler (#20476)Bung2022-10-011-0/+12
* fix #2614 improve error message when array of proc calling convention… (#20...Bung2022-09-262-9/+33
* defaults to ORC (#19972)ringabout2022-09-231-1/+2
* Improve error message when instantiating generics with object constructor (#2...Bung2022-09-211-0/+5
* report expression has no type other than has to be used (or discarded… (#20...Bung2022-09-201-0/+6
* fix #19882 Improve error message when instantiating generics that lac… (#20...Bung2022-09-191-0/+10
* minor improvements to follow up recent PRs (#20342)metagn2022-09-142-2/+2
* remove deprecated type pragma syntax, fix bugs that required it (#20199)metagn2022-09-031-1/+1
* [Testament] Extend and document message testing aids (#19996)quantimnot2022-09-011-13/+12
* remove unused sfProcvar, "procvar" mentions (#20204)metagn2022-08-241-1/+1
* fixes #18983 #5282 #13008; recursive types casue infinite type (#20172)ringabout2022-08-232-0/+12
* remove a special case in sigmatch; distinct pointer types no longer match `ni...ringabout2022-08-231-0/+23
* Stop type aliases from inheriting sfUsed (#19861)quantimnot2022-06-041-13/+40
* deprecate unsafeAddr; extend addr (#19373)flywind2022-01-162-2/+2
* style usages part one (openarray => openArray) (#19321)flywind2022-01-043-4/+4
* asynchttpserver: ipv6 support (#18706)Emery Hemingway2021-08-181-1/+1
* implements overloadable enum values; WIP (#18470)Andreas Rumpf2021-07-281-1/+1
* rename nimFpRoundtrips => nimPreviewFloatRoundtrip (#18566)Timothee Cour2021-07-231-1/+1
* make -d:nimFpRoundtrips work consistently in vm vs rt, fix #18400, etc (#18531)Timothee Cour2021-07-201-8/+6
* make dragonbox opt-in via -d:nimFpRoundtrips (#18504)Andreas Rumpf2021-07-161-6/+8
* improve `--declaredLocs` to help disambiguate types (generics, aliases etc) (...Timothee Cour2021-07-083-4/+96
* Make procedure mismatch more informative with pragma/call convention mismatch...Jason Beetham2021-07-061-0/+74
* float parsing: Add test for a fixed issue (#18232)Kaushal Modi2021-06-241-11/+18
* fix #18332: XDeclaredButNotUsed hints now in deterministic order (#18336)Timothee Cour2021-06-241-11/+13
* fix #18327 (#18328)flywind2021-06-221-0/+5
5339346'>^
419e4aa5 ^

d88232a3 ^
e01ea652 ^

ae943ecb ^
f8e96a97 ^


d88232a3 ^
f8e96a97 ^
4c05e43d ^

728fb838 ^


b624bd94 ^



e01ea652 ^

728fb838 ^

fa704bab ^
fa704bab ^




79355449 ^


fa704bab ^
79355449 ^
fa704bab ^

4c05e43d ^

4c05e43d ^
f5e9c01e ^
4c05e43d ^
d88232a3 ^

ae943ecb ^

f1352f40 ^
ae943ecb ^
2d98e85f ^

d494f019 ^
d88232a3 ^

a396b3a0 ^



be7c282c ^



d88232a3 ^

9506fb8e ^
c7a36d0a ^
0b306138 ^
91e5b943 ^
ee4687c3 ^
5645f266 ^
4070e6c9 ^

ee4687c3 ^
91e5b943 ^

ee4687c3 ^
9506fb8e ^

90dc5f6a ^

06152bdc ^
117028c3 ^
8d89c6f3 ^
117028c3 ^

ee4687c3 ^

06152bdc ^

9506fb8e ^
d9d3243b ^



7626fd1d ^
5822dff7 ^
be7c282c ^

7626fd1d ^


be7c282c ^
7626fd1d ^


be7c282c ^

d9d3243b ^



7626fd1d ^
334e81f2 ^
be7c282c ^
7626fd1d ^
be7c282c ^
7626fd1d ^
334e81f2 ^
e0bc0ff6 ^
be7c282c ^






d88232a3 ^

270ac053 ^

b4b0eb24 ^

ea87d005 ^
d88232a3 ^
e85d44ae ^





d88232a3 ^
42fd3690 ^
d88232a3 ^


42fd3690 ^
d88232a3 ^

270ac053 ^

b4b0eb24 ^

d88232a3 ^


b4ed1800 ^
42fd3690 ^
d88232a3 ^
6a40e8e0 ^

14c8ed43 ^

f45f3c73 ^



ce421875 ^



7d9ae552 ^
d88232a3 ^




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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
                                                                 
 



                                                                      
 






                                                                       
 
         
          
             
              
 
                                             
                                                  
                                               
                                   
 



                                                                  
















                                                                               

                               
                         
                                              
                                                                             
                                                                          
 




                                      
                                           
                                                          
                                          
 
                                                         
 
                             
                                                                                        
                                   
                                  
                                      
 
                               
                               
                                    



                                                                             

                                           
 

                                                                               
 


                                             
                                  
 

                                     


                                  



                                          

                                                       

                               
                                         




                                                


                                                                             
                             
                                                   

                                                    

                                                             
                              
                                                  
 

                                         

                                                             
                                     
                              

                                                               
 

                                       



                                         



                                                  

                                                         
 
                                                          
                                        
                                         
                                  
 

                                        
                                

                                    
                             

                              

                                  
                                
                            
                                                                              

                                                     

                                            

                                    
 



                                            
                               
                                      

                                                                         


                                                           
                                          


                                                           

                                               



                                                                                 
                                                              
                                                                                 
                                                 
                     
                                                                      
                                   
                                                                                         
                                                         






                                                                          

                        

                                                  

                              
 
                         





                                        
                                                                              
                                


                                    
                                       

                              

                                         

                                                         


                                                       
                                                       
                                   
                                               

                                                                   

                                                                         



                                                                                       



                                                                                             
                                  




                                                                               
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import curses
import _curses

from .displayable import DisplayableContainer
from ranger.gui.curses_shortcuts import ascii_only
from ranger.container.keymap import CommandArgs
from .mouse_event import MouseEvent

TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt",
		"rxvt-256color", "rxvt-unicode", "aterm", "Eterm",
		"screen", "screen-256color")

MOUSEMASK = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION

def _setup_mouse(signal):
	if signal['value']:
		curses.mousemask(MOUSEMASK)
		curses.mouseinterval(0)

		## this line solves this problem:
		## If an action, following a mouse click, includes the
		## suspension and re-initializion of the ui (e.g. running a
		## file by clicking on its preview) and the next key is another
		## mouse click, the bstate of this mouse event will be invalid.
		## (atm, invalid bstates are recognized as scroll-down)
		curses.ungetmouse(0,0,0,0,0)
	else:
		curses.mousemask(0)

class UI(DisplayableContainer):
	is_set_up = False
	load_mode = False
	def __init__(self, env=None, fm=None):
		self._draw_title = os.environ["TERM"] in TERMINALS_WITH_TITLE
		os.environ['ESCDELAY'] = '25'   # don't know a cleaner way

		if env is not None:
			self.env = env
		if fm is not None:
			self.fm = fm

		self.win = curses.initscr()
		self.env.keymanager.use_context('browser')
		self.env.keybuffer.clear()

		DisplayableContainer.__init__(self, None)

	def initialize(self):
		"""initialize curses, then call setup (at the first time) and resize."""
		self.win.leaveok(0)
		self.win.keypad(1)
		self.load_mode = False

		curses.cbreak()
		curses.noecho()
		curses.halfdelay(20)
		try:
			curses.curs_set(int(bool(self.settings.show_cursor)))
		except:
			pass
		curses.start_color()
		curses.use_default_colors()

		self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
		_setup_mouse(dict(value=self.settings.mouse_enabled))

		if not self.is_set_up:
			self.is_set_up = True
			self.setup()
		self.update_size()

	def suspend(self):
		"""Turn off curses"""
		self.win.keypad(0)
		curses.nocbreak()
		curses.echo()
		try:
			curses.curs_set(1)
		except:
			pass
		if self.settings.mouse_enabled:
			_setup_mouse(dict(value=False))
		curses.endwin()

	def set_load_mode(self, boolean):
		boolean = bool(boolean)
		if boolean != self.load_mode:
			self.load_mode = boolean

			if boolean:
				# don't wait for key presses in the load mode
				curses.cbreak()
				self.win.nodelay(1)
			else:
				self.win.nodelay(0)
				curses.halfdelay(20)

	def destroy(self):
		"""Destroy all widgets and turn off curses"""
		self.suspend()
		DisplayableContainer.destroy(self)

	def handle_mouse(self):
		"""Handles mouse input"""
		try:
			event = MouseEvent(curses.getmouse())
		except _curses.error:
			return
		if not self.console.visible:
			DisplayableContainer.click(self, event)

	def handle_key(self, key):
		"""Handles key input"""

		if hasattr(self, 'hint'):
			self.hint()

		if key < 0:
			self.env.keybuffer.clear()
			return

		if DisplayableContainer.press(self, key):
			return

		self.env.keymanager.use_context('browser')
		self.env.key_append(key)
		kbuf = self.env.keybuffer
		cmd = kbuf.command

		self.fm.hide_bookmarks()

		if kbuf.failure:
			kbuf.clear()
			return
		elif not cmd:
			return

		self.env.cmd = cmd

		if cmd.function:
			try:
				cmd.function(CommandArgs.from_widget(self.fm))
			except Exception as error:
				self.fm.notify(error)
			if kbuf.done:
				kbuf.clear()
		else:
			kbuf.clear()

	def handle_keys(self, *keys):
		for key in keys:
			self.handle_key(key)

	def handle_input(self):
		key = self.win.getch()
		if key is 27 or key >= 128 and key < 256:
			# Handle special keys like ALT+X or unicode here:
			keys = [key]
			previous_load_mode = self.load_mode
			self.set_load_mode(True)
			for n in range(4):
				getkey = self.win.getch()
				if getkey is not -1:
					keys.append(getkey)
			if len(keys) == 1:
				keys.append(-1)
			if self.settings.xterm_alt_key:
				if len(keys) == 2 and keys[1] in range(127, 256):
					keys = [27, keys[1] - 128]
			self.handle_keys(*keys)
			self.set_load_mode(previous_load_mode)
			if self.settings.flushinput and not self.console.visible:
				curses.flushinp()
		else:
			# Handle simple key presses, CTRL+X, etc here:
			if key > 0:
				if self.settings.flushinput and not self.console.visible:
					curses.flushinp()
				if key == curses.KEY_MOUSE:
					self.handle_mouse()
				elif key == curses.KEY_RESIZE:
					self.update_size()
				else:
					if not self.fm.input_is_blocked():
						self.handle_key(key)

	def setup(self):
		"""
		Called after an initialize() call.
		Override this!
		"""

	def redraw(self):
		"""Redraw all widgets"""
		self.poke()
		self.draw()
		self.finalize()

	def redraw_window(self):
		"""Redraw the window. This only calls self.win.redrawwin()."""
		self.win.erase()
		self.win.redrawwin()
		self.win.refresh()
		self.win.redrawwin()
		self.need_redraw = True

	def update_size(self):
		"""
		Update self.env.termsize.
		Extend this method to resize all widgets!
		"""
		self.env.termsize = self.win.getmaxyx()

	def draw(self):
		"""Draw all objects in the container"""
		self.win.touchwin()
		DisplayableContainer.draw(self)
		if self._draw_title and self.settings.update_title:
			cwd = self.fm.env.cwd.path
			if cwd.startswith(self.env.home_path):
				cwd = '~' + cwd[len(self.env.home_path):]
			if self.settings.shorten_title:
				split = cwd.rsplit(os.sep, self.settings.shorten_title)
				if os.sep in split[0]:
					cwd = os.sep.join(split[1:])
			try:
				sys.stdout.write("\033]2;ranger:" + cwd + "\007")
			except UnicodeEncodeError:
				sys.stdout.write("\033]2;ranger:" + ascii_only(cwd) + "\007")
		self.win.refresh()

	def finalize(self):
		"""Finalize every object in container and refresh the window"""
		DisplayableContainer.finalize(self)
		self.win.refresh()