summary refs log tree commit diff stats
path: root/tests/destructor
Commit message (Expand)AuthorAgeFilesLines
* use doAssert in tests (#16486)flywind2020-12-281-8/+8
* fixes #16365 [backport] (#16381)Andreas Rumpf2020-12-171-1/+31
* testament: error instead of silently ignore invalid targets; remove pointless...Timothee Cour2020-12-142-2/+2
* testament spec: remove errmsg alias of errormsg (#16188)Timothee Cour2020-11-291-1/+1
* make megatest consistent with unjoined tests wrt newlines, honor newlines in ...Timothee Cour2020-11-281-1/+1
* fix #15825 (#15894)cooldome2020-11-091-0/+11
* Add testcase for #14601 (#15677)Clyybber2020-10-221-1/+45
* renamed '=' to '=copy' [backport:1.2] (#15585)Andreas Rumpf2020-10-155-5/+5
* fixes #14983 (#15320)Andreas Rumpf2020-09-251-1/+14
* fixes #15361 (#15401)Andreas Rumpf2020-09-242-7/+10
* disable sink inference, only enable it for the stdlib. Reason: better source ...Andreas Rumpf2020-07-281-0/+1
* An optimizer for ARC (#14962)Andreas Rumpf2020-07-153-7/+15
* injectdestructors fixes and refactor (#14964)Clyybber2020-07-141-1/+0
* fixes #14925 (#14947)Andreas Rumpf2020-07-091-1/+8
* progressAraq2020-07-081-1/+1
* scoped memory management (#14790)Andreas Rumpf2020-07-041-19/+19
* Fix #14647 (#14776)Clyybber2020-06-281-1/+7
* Add testcases for #11811 and #14315 (#14726)Clyybber2020-06-191-1/+11
* Fix #14568 (#14583)Clyybber2020-06-071-0/+1
* fix #14421 items uses lent T (#14447)Timothee Cour2020-05-297-7/+7
* ARC/ORC: optimize s.setLen(0) to match the old runtime's behaviour (#14423)Andreas Rumpf2020-05-211-1/+1
* Small improvements for string and char repr with gc:arc (#14400)Clyybber2020-05-201-1/+1
* fix #14294 (#14301)cooldome2020-05-111-1/+25
* fix #14217 (#14218)cooldome2020-05-051-0/+26
* fixes #14159 [backport:1.2]Araq2020-05-021-0/+33
* fixes #14054 [backport:1.2] (#14061)Andreas Rumpf2020-04-301-1/+1
* Error -> Defect for defects (#13908)Jacek Sieka2020-04-283-8/+8
* fixes a critical =trace generation bug (see test case) (#14140)Andreas Rumpf2020-04-271-0/+16
* new implementations for --gc:orc (#14121)Andreas Rumpf2020-04-275-0/+6
* Implements RFCs #209 (#13995)cooldome2020-04-161-7/+3
* fixes #13782 (#13834)Andreas Rumpf2020-04-011-1/+21
* faster CIs (#13803)Miran2020-03-301-3/+3
* arc optimizations (#13325)Andreas Rumpf2020-03-184-3/+8
* rewritten goto based exception handling; much cleaner implementation;… (#13...Andreas Rumpf2020-03-171-0/+69
* Fixes #13659 (#13674)cooldome2020-03-171-1/+25
* fixes #12747 [backport] (#13651)cooldome2020-03-162-2/+2
* catchable defects (#13626)Andreas Rumpf2020-03-121-0/+52
* fixes #13436 (#13615)Andreas Rumpf2020-03-101-0/+10
* fixes #13599 (#13614)Andreas Rumpf2020-03-091-0/+39
* sink parameter inference for types that have destructors (#13544)Andreas Rumpf2020-03-042-2/+6
* fixes #13457 (#13458)Andreas Rumpf2020-02-211-1/+8
* Repr v2 progress (#13268)cooldome2020-01-281-1/+1
* ARC: remove unnecessary codeAraq2020-01-261-4/+3
* contributing docs: symbols need package prefix; changed allocStats to nimAllo...Timothee Cour2020-01-258-8/+8
* Removed lib/system/allocators.nim. seqs_v2 and strs_v2 now uses allocShared0....Ico Doornekamp2020-01-239-56/+31
* fixes #13195 (#13198)cooldome2020-01-201-0/+25
* Revert "fixes #13195"Andrii Riabushenko2020-01-191-25/+0
* revert last commitAndrii Riabushenko2020-01-191-0/+25
* more on arc codegen (#13178)cooldome2020-01-191-1/+20
* make sink operator optional (#13068)cooldome2020-01-172-12/+4
href='#n22'>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

                                                                 
 
                                                                  
 
          



                                                            
                              
 
 
                  



























                                                             
                            






                                                         
                                 



























                                                                          
                   











                                                  


                    
 
                                                                                
                                            
 
                                      


                                                                   
 

                                  
 

                                              
 







                                  
 

                            
 



                                        
                                               




















                                                                                
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

from __future__ import (absolute_import, division, print_function)

import sys

from ranger.ext.widestring import WideString, utf_char_width


PY3 = sys.version_info[0] >= 3


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

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

    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 self.left:
                leftsize -= len(self.left.pop(-1))
                if leftsize + rightsize <= wid:
                    break
            sumsize = leftsize + rightsize

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

        if sumsize < wid:
            self.fill_gap(' ', (wid - sumsize), gapwidth=True)

    def shrink_from_the_left(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()
        oversize = leftsize + rightsize - wid
        if oversize <= 0:
            return self.fill_gap(' ', wid, gapwidth=False)

        # Shrink items to a minimum size until there is enough room.
        for item in self.left:
            if not item.fixed:
                itemlen = len(item)
                if oversize > itemlen - item.min_size:
                    item.cut_off_to(item.min_size)
                    oversize -= (itemlen - item.min_size)
                else:
                    item.cut_off(oversize)
                    break
        return None

    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 __init__(self, base_color_tag):  # pylint: disable=super-init-not-called
        self.base_color_tag = base_color_tag

    def add(self, string, *lst, **kw):
        colorstr = ColoredString(string, self.base_color_tag, *lst)
        colorstr.__dict__.update(kw)
        self.append(colorstr)

    def add_space(self, n=1):
        self.add(' ' * n, 'space')

    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 += item.min_size
        return n


class ColoredString(object):

    def __init__(self, string, *lst):
        self.string = WideString(string)
        self.lst = lst
        self.fixed = False
        if not string or not self.string.chars:
            self.min_size = 0
        elif PY3:
            self.min_size = utf_char_width(string[0])
        else:
            self.min_size = utf_char_width(self.string.chars[0].decode('utf-8'))

    def cut_off(self, n):
        if n >= 1:
            self.string = self.string[:-n]

    def cut_off_to(self, n):
        if n < self.min_size:
            self.string = self.string[:self.min_size]
        elif n < len(self.string):
            self.string = self.string[:n]

    def __len__(self):
        return len(self.string)

    def __str__(self):
        return str(self.string)