IsPartial returns true if the cell at the specified point holds a part of a full width rune from a previous cell. See http://www.unicode.org/reports/tr11/.
(p image.Point)
| 134 | // full width rune from a previous cell. See |
| 135 | // http://www.unicode.org/reports/tr11/. |
| 136 | func (b Buffer) IsPartial(p image.Point) (bool, error) { |
| 137 | size := b.Size() |
| 138 | ar, err := area.FromSize(size) |
| 139 | if err != nil { |
| 140 | return false, err |
| 141 | } |
| 142 | |
| 143 | if !p.In(ar) { |
| 144 | return false, fmt.Errorf("point %v falls outside of the area %v occupied by the buffer", p, ar) |
| 145 | } |
| 146 | |
| 147 | if p.X == 0 && p.Y == 0 { |
| 148 | return false, nil |
| 149 | } |
| 150 | |
| 151 | prevP := image.Point{p.X - 1, p.Y} |
| 152 | if prevP.X < 0 { |
| 153 | prevP = image.Point{size.X - 1, p.Y - 1} |
| 154 | } |
| 155 | |
| 156 | prevR := b[prevP.X][prevP.Y].Rune |
| 157 | switch rw := runewidth.RuneWidth(prevR); rw { |
| 158 | case 0, 1: |
| 159 | return false, nil |
| 160 | case 2: |
| 161 | return true, nil |
| 162 | default: |
| 163 | return false, fmt.Errorf("buffer cell %v contains rune %q which has an unsupported rune with %d", prevP, prevR, rw) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // RemWidth returns the remaining width (horizontal row of cells) available |
| 168 | // from and inclusive of the specified point. |